r - How to use the envir argument in knit_child? -
i'm writing r package in have such rmd template:
child.rmd:
```{r} print(x) ```
and such function:
child <- function(){ myenv <- new.env() assign("x", 0, envir=myenv) # knit: output <- knit_child("child.rmd", envir=myenv) return(output) }
then knit such file :
```{r, echo=false} library(mypackage) ``` `r child()`
but doesn't work, output is:
print(x) ## error: object 'x' not found
below self-contained example, without involving package, don't know whether equivalent , need package structure:
```{r} child <- function(){ myenv <- new.env() assign("x", 0, envir=myenv) # knit: output <- knit_child("child.rmd", envir=myenv) return(output) } ``` `r child()`
this should fixed in development version of knitr (>= v1.6.3): knit_child()
has gained new argument envir
, , can pass arbitrary environment it.
Comments
Post a Comment