Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Markdown not finding params when knitting

Tags:

r

r-markdown

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
like image 805
jerH Avatar asked Dec 12 '25 13:12

jerH


1 Answers

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...

like image 126
jerH Avatar answered Dec 15 '25 03:12

jerH