The chunk cache parameter does not save all variables defined in the block for languages ββother than R This, however, is the preservation of printed outputs, so if you are calculating something that takes some time, any results do not need to be re-read. On the knitr website:
With the exception of engine='R' (default), all chunks are executed in separate sessions, so variables cannot be directly separated. If we want to use objects created in previous pieces, we usually need to write them to files (as side effects). For the bash engine, we can use Sys.setenv() to export variables from R to bash (example).
You can save multiple values ββin a shell environment and get these values ββfrom other cells by reading the environment. This approach Yihui took an example of Polyglot . So, for Python, if you can format the value as a string and pass it to Sys.setenv() , you can use that value in another cell (executed as a separate Python session) by calling sys.getenv() .
Although, I was a bit confused about the approach taken with the C and Fortran engines. It seems that they have access to compiled functions in later snippets using some function called .C() or called .Fortran() . But it looks like Python has no equivalent.
pneumatics
source share