r - knitr - Python engine cache option not working -


yihui gives example of using cache option different engines

https://github.com/yihui/knitr-examples/blob/master/023-engine-python.rmd

i can't seem work python.

the following works

```{r,engine='python',cache=true} x=10 print x ``` 

but doesn't work

```{r,engine='python',cache=true} x = 10 ```  ```{r,engine='python',cache=true} print x ``` 

anyone have idea?

the chunk option cache doesn't save variables defined in block languages other r. is, though, saving printed outputs, if compute takes while, results not need re-computed. knitr website:

except engine='r' (default), chunks executed in separate sessions, variables cannot directly shared. if want make use of objects created in previous chunks, have write them files (as side effects). bash engine, can use sys.setenv() export variables r bash (example).

it's possible save few values in shell's environment, , retrieve values other cells reading environment. approach yihui took in polyglot example. so, python, if can format value string , pass sys.setenv(), use value in cell (run separate python session) calling sys.getenv().

though, mildly confused approach taken c , fortran engines. seem have access compiled functions in later chunks using function called .c() or function called .fortran(). seems python not have equivalent.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -