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

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -