This seems like a very basic question, but somehow I cannot find the solution anywhere. I am trying to pass variables to R markdown child documents.
In the parent document, I have this chunk:
```{r}
var1 = "test-var1!"
cat(knit_child("child.Rmd"), sep = "\n")
```
In the child document, if I use ls()
, I can see var1
is in the environment. However, if I try to use var1
, I get a knit error:
Error in str(var1) : object 'var1' not found
Calls: <Anonymous> ... withCallingHandlers -> withVisible -> eval -> eval -> str
I tried knitting in RStudio and on the command line.
Is there a way to use objects in the child document?