Open tmastny opened 6 years ago
I'm afraid I'll have to defer this issue to @kevinushey (author of the python engine in reticulate).
For what it's worth, I never tried wiring in cache support into the reticulate engine as I wasn't exactly sure what that would entail, but it sounds like we'd need:
pickle
?)Thanks @kevinushey. Something else to look into is dill
which extends pickle
. From the readme:
Hence, it would be feasable to save a interpreter session, close the interpreter, ship the pickled file to another computer, open a new interpreter, unpickle the session and thus continue from the 'saved' state of the original interpreter session.
And the reason I opened the issue here is because I think knitr
will also require some refactoring to allow specific engines to handle caching. Right now all caching is handled by the cache
methods in R/block.R
call_block
for loading and block_cache
for saving.
If this is something you'd like for reticulate, I'd be interested in helping out with PRs. I'd like to be able write Python with rmarkdown using all the knitr features.
I'd definitely be open to reviewing a PR, but it seems like this will be tough to get right and I unfortunately won't have that much time to help with the actual implementation in the coming months.
Hi! I'm working on it (by sheer necessity). There are some some serious problems on the dill
package at the moment, but I'm also updating some currently broken logic in the code proposed by @tmastny and it is mostly working by now, with some edge cases requiring monkey patches. As soon as the bugs on dill
are fixed, I'll send a new pull request based on his code.
Beyond basic usage, I find that a Python cache engine for knitr
is essential. We need this, folks! :rocket:
I think whether or not this is a knitr or reticulate bug depends on the knitr engine API, which I do not completely understand. I carefully searched for this bug in the knitr and reticulate issues and didn't see anything, so I apologize if this is already known.
The bug
Suppose we have the following file called
python_test.Rmd
:Quitting from lines 19-20 (python_test.Rmd) Error in py_run_string_impl(code, local, convert) : NameError: name 'x' is not defined
Detailed traceback: File "", line 1, in
Calls: ... force -> py_run_string -> py_run_string_impl -> .Call
Execution halted
Matrix products: default BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages: [1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached): [1] compiler_3.4.1 backports_1.1.2 magrittr_1.5.0 rsconnect_0.8.5 [5] rprojroot_1.3-2 htmltools_0.3.6 tools_3.4.1 yaml_2.1.16
[9] Rcpp_0.12.15 stringi_1.1.6 rmarkdown_1.8.10 knitr_1.19.2
[13] stringr_1.2.0 digest_0.6.15 evaluate_0.10.1