Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201839

Have different .RMD file and output file names

$
0
0

I'm having troubles name my output PDF file from my "Knit with Parameters" RMD file. my YAML header looks something like this:

---
title: "Discounting"
output: pdf_document 
#with more parameters for later
---

My file is called "Discounting Script.rmd"

Now, when I run my rmd file, the output PDF is called "Discounting Script.pdf" I'd like to make it something like "Discounting "& Sys.Date() & ".pdf" but I seem to be unable to. I could "save as" for the rmd file if I'm able to do that somewhere in the code below to get a similar name. I can't use rmarkedown::render because I have to knit with parameters (and I've tried the render, and I only get errors)

I want to add a part under output so it looks something like this:

---
title: "Discounting"
output: pdf_document
     output_file: "Discounting "& Sys.Date() & ".pdf"
---

I've also tried"

 ---
    title: "Discounting"
    output: pdf_document
         output_file: paste0("Discounting ",Sys.Date(),".pdf")
    ---

But neither work and they both throw errors. This should be a simple action to complete, but I can't find anything online that helps me.

Here's the 'whole file' everything under the YAML header works fine, it's just the header I have problems with.

---
title: " Discounting"
output: pdf_document 
  output_file: `r paste0("Discounting ", Sys.Date(), ".pdf")`
params:
  CPI: 
    label: "CPI:"
    value: .02
  Federal_Bonds: 
    input: slider
    label: "Federal Bonds are on rows:"
    min: 6
    max: 12
    value: [7,8]
    step: 1
    round: 1
    dragRange: true
  Provincial_Bonds:  
    label: "Provincial Bonds are on rows:"
    min: 10
    max: 35
    step: 1
    round: 1
    value: [15, 28]
  Corporate_Bonds:  
    label: "Corporate Bonds are on rows:"
    value: [35,86]
    min: 30
    max: 100
    round: 1
    step: 1
---

```{r eval = TRUE, echo= FALSE, warning = FALSE, results = "asis", message = FALSE}
Federal_Start <- params$Federal_Bonds[1]
Federal_End <-params$Federal_Bonds[2]
Provincial_Start <- params$Provincial_Bonds[1]
Provincial_End <- params$Provincial_Bonds[2]
Corporate_Start <- params$Corporate_Bonds[1]
Corporate_End  <- params$Corporate_Bonds[2]
CPI <- params$CPI
```


```{r eval = TRUE, echo= FALSE, warning = FALSE, results = "asis", message = FALSE}
#loading packages
library(plyr)
library(dplyr)
library(kableExtra)
library(scales)
library(ggplot2)
library(RODBC)
library(data.table)
library(DT)
library(treemapify)
library(devtools)
library(digest)
library(plotly)
library(shiny)
library(ggrepel)
library(readxl)
library(tvm)
library(jrvFinance)
library(lubridate)
```

```{r eval = TRUE, echo= FALSE, warning = FALSE, results = "asis", message = FALSE}
printSectionTitle <- function (title) {
 cat("","\n\n")
 template <- title
 cat(sprintf(template),"  \n")
}
```

```{r eval = TRUE, echo= FALSE, warning = FALSE, results = "asis", message = FALSE} 
port_table <- c(Federal_Start, Federal_End, Provincial_Start, Provincial_End, Corporate_Start, Corporate_End, CPI)
```


```{r eval = TRUE, echo= FALSE, warning = FALSE, results = "asis", message = FALSE}
#Formatting the tables and creating a pretty report
printSectionTitle(sprintf("# %s","The Company"))
printSectionTitle(sprintf("# %s","Merging of Bond Portfolio with Other Risk Free Assets"))
printSectionTitle(sprintf("## %s",paste0("as at ", format(as.Date(Start_Date), "%d %B %Y"))))


colnames(port_table) <- c("","")
port_kable <- kable(port_table, align = "r",col.names = NA)
port_kable <- row_spec(port_kable, row = c(4, 7), bold = TRUE, underline = TRUE)
print(kable_styling(port_kable, bootstrap_options = "striped",latex_options = "hold_position", position ="left"))
```

The above code gets this error Error in yaml::yaml.load(..., eval.expr = TRUE) : Scanner error: mapping values are not allowed in this context at line 3, column 14 Calls: ... parse_yaml_front_matter -> yaml_load -> Execution halted


Viewing all articles
Browse latest Browse all 201839

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>