When I try to knit the following document
----
title: "jerHW52"
output: html_document
params:
missiontype: "Successful.Unmanned"
---
```{r warning=FALSE,echo=FALSE}
knitr::opts_chunk$set(echo=FALSE)
library(tidyr)
library(ggplot2)
Launch_Data<-read.csv("NASA_Launch_Data.csv",header=TRUE)
NASA_Launch_Data<- Launch_Data %>% filter(Launch_Data$Type==params$missiontype)
ggplot(NASA_Launch_Data, aes(x=Year, y=Missions)) + geom_line()
```
I get the following error
Error in filter(., Launch_Data$Type == params$missiontype) : object
'params' not found Calls: ... _fseq -> freduce ->
withVisible -> -> filter Execution halted
Why would it not be able to find params?
Here is the start of the data in NASA_Launch_Data.csv
"","Year","Type","Missions"
"1",1957,"Successful.Unmanned",3
"2",1958,"Successful.Unmanned",28
"3",1959,"Successful.Unmanned",23
"4",1960,"Successful.Unmanned",40
"5",1961,"Successful.Unmanned",48
"6",1962,"Successful.Unmanned",76
"7",1963,"Successful.Unmanned",67
"8",1964,"Successful.Unmanned",99
"9",1965,"Successful.Unmanned",119
"10",1966,"Successful.Unmanned",129
The answer is that I'm an idiot....
Note the YAML header at the top of my document
----
title: "jerHW52"
output: html_document
params:
missiontype: "Successful.Unmanned"
---
There are four dashes on the first line, not three as there should be. Remove one and everything works...
Related
I am trying to create a PDF from R. I am successful from within RStudio (choosing "Knit to PDF"), but I get an error invoking from R (either with ctl-enter in Rstudio or with Rscript --vanilla invoke_from_R.R from the command line). My actual need is to create from the command line.
For example:
invoke_from_R.Rmd
---
title: "Lumber Jacks"
author: "Washington Irving"
date: "2022-09-19"
output:
pdf_document:
keep_tex: true
keep_md: true
dev: pdf
includes:
in_header: invoke_from_R_preamble.tex
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
## Where are we?
Dove siamo?
invoke_from_R_preamble.tex
\newcommand\T{\rule{0pt}{2.6ex}} % Top strut
\newcommand\B{\rule[-1.2ex]{0pt}{0pt}} % Bottom strut
invoke_from_R.R
rmarkdown::render(
input = "invoke_from_R.Rmd"
, output_file = "invoke_from_R.pdf"
, output_format = rmarkdown::pdf_document(
rmarkdown::includes(in_header = "invoke_from_R_preamble.tex"),
toc = TRUE
, toc_depth = 2
, number_sections = FALSE
, keep_md = TRUE
, keep_tex = TRUE
, fig_width = 6.5
, fig_height = 4.5
, fig_crop = FALSE
)
)
The error that I get is:
$ Rscript --vanilla invoke_from_R.R
Error in !implicit_figures : invalid argument type
Calls: <Anonymous> ... <Anonymous> -> output_format -> pandoc_options -> from_rmarkdown
Execution halted
I have not yet found a workaround.
When I comment out this line:
rmarkdown::includes(in_header = "invoke_from_R_preamble.tex"),
I don't get the error, but I need to use the preamble because some of my LaTeX macros get processed even when I use the setting that is supposed to prevent this.
I am using (on Linux):
R version 4.2.1 (2022-06-23)
rmarkdown 2.14
Suggestions?
Thank you.
I have a directory Project/Package/R with three files: script.R, knitr.Rmd and quarto.qmd.
This is knitr.Rmd:
---
title: "Essai"
output: pdf_document
---
```{r, include=FALSE}
library(here)
knitr::opts_knit$set(root.dir = here())
source(here("Package","R","script.R"), local = knitr::knit_global())
```
This is quarto.qmd:
---
title: "Essai"
format:
pdf:
toc: true
toc-depth: 2
---
```{r, include=FALSE}
library(here)
knitr::opts_knit$set(root.dir = here())
source(here("Package","R","script.R"), local = knitr::knit_global())
```
All is OK with knitr compilation, but quarto can't find the script R:
Quitting from lines 10-14 (stack.qmd)
Erreur dans readChar(con, 5L, useBytes = TRUE) :
impossible d'ouvrir la connexion
Appels : .main ... source -> withVisible -> eval -> eval -> load -> readChar
Exécution arrêtée
What is wrong? Thank you in advance.
I'm trying to pass variables to rmarkdown report as params but i'm not able to render it in the report
the below one is my code the my_value param is dataframe having only single row
---
title
output:
pdf_document: default
output:
pdf_document:
keep_tex: true
classoption: svgnames
header-includes:
- \usepackage{amsfonts,amssymb,amsmath}
params:
my_class:"smile"
my_value: data$percent
--
`r params$my_value` is the total percentage of customers
`r params$my_class` is product which has been doing better
The YAML header you're using isn't valid.
title tag should finish by : and have a value : title: "test"
output should only be used once
finish header with ---
Try:
---
title: "test"
output:
pdf_document:
keep_tex: true
header-includes:
- \usepackage{amsfonts,amssymb,amsmath}
classoption: svgnames
params:
my_class: "smile"
my_value: NA
---
Regarding parameters, you can't directly use data$percent as parameter value in YAML header.
Knitting is done in a new environment, data$percent doesn't exist in it.
In YAML, you could use following settings:
params:
my_class:"smile"
my_value: NA
In calling script:
# data definition
data <- ...
params <- list(
my_class = "more smiles",
my_value = data$percent
)
rmarkdown::render("MyDocument.Rmd", params = params)
For more information : https://bookdown.org/yihui/rmarkdown/params-knit.html
I'm trying to loop through a list of employee IDs to create a report for each id.
I know I have to declare the parameter in the YAML but I'm getting a scanner error.
---
title: "Employee Record"
params:
MASTER_ID: !r uniqueID
output: pdf_document
---
**Employee ID:** `r params$MASTER_ID`
The field of employee ids in the dataset is called MASTER_ID and uniqueID is just a list of each unique employee id (length = 880)
The error I'm getting is:
Error in yaml::yaml.load(string, ...) :
Scanner error: while scanning a simple key at line 3, column 1 could not find expected ':' at line 4, column 1
I don't have any extra white spaces or anything so i'm not sure what I'm missing
To follow up on what others have already said, it is best to call your Rmd from a separate R file using the rmarkdown::render function. This also allows you to easily control the file naming and output location.
employees <- 1:10
for (i in employees) {
rmarkdown::render("test_pdf.Rmd",
params = list(MASTER_ID = i),
output_file = paste0('employee-', i, ".pdf"),
output_dir = '/reports')
}
With test_pdf.Rmd containing:
title: "Employee Record"
params:
MASTER_ID:
value: 1
output: pdf_document
---
**Employee ID:** `r params$MASTER_ID`
I am trying to add table of contentsinto tufte_handout template in rmarkdown package as it is suggest here at the bottom of a page but when I creat yaml like this:
---
title: "Tufte Handout"
author: "John Smith"
date: "August 13th, 2014"
output:
rmarkdown::tufte_handout:
toc: true
---
I recieve an error like this:
Error in (function (fig_width = 4, fig_height = 2.5, fig_crop = TRUE, :
unused argument (toc = TRUE)
Calls: <Anonymous> -> create_output_format -> do.call -> <Anonymous>
Execution halted
Anyone knows how to handle this issue?