Skip to content

Commit 3805536

Browse files
committed
changes from feedback on knitr #1518 with updated tests
1 parent bd68b2c commit 3805536

File tree

4 files changed

+10
-10
lines changed

4 files changed

+10
-10
lines changed

R/knitr-engine.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,18 +314,19 @@ save_python_session <- function(cache_path) {
314314
#' Typically, this will be set within a document's setup chunk, or by the
315315
#' environment requesting that Python chunks be processed by this engine.
316316
#'
317-
#' @param cache_path
318-
#' The path to save the chunk cache, as provided by `knitr` during chunk execution.
317+
#' @param options
318+
#' List of chunk options provided by `knitr` during chunk execution.
319+
#' Contains the caching path.
319320
#'
320321
#' @export
321-
cache_eng_python <- function(cache_path) {
322+
cache_eng_python <- function(options) {
322323
module <- tryCatch(import("dill"), error = identity)
323324
if (inherits(module, "error")) {
324325
if (module$message == "ImportError: No module named dill") return()
325326
stop(module$message)
326327
}
327328

328-
module$load_session(filename = paste0(cache_path, ".pkl"))
329+
module$load_session(filename = paste0(options$hash, ".pkl"))
329330
}
330331

331332

man/cache_eng_python.Rd

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/resources/eng-reticulate-cache-test.Rmd

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ title: "Using reticulate's Python Engine with knitr"
55
```{r setup, include = FALSE}
66
library(reticulate)
77
knitr::opts_chunk$set(cache=TRUE)
8-
knitr::knit_engines$set(python = eng_python)
9-
knitr::cache_engines$set(python = cache_eng_python)
108
```
119

1210
Cache can handle changes to second chunk:

tests/testthat/test-python-cache-engine.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ test_that("An R Markdown document builds if a cache is modified", {
2525
old_var <- "1"
2626
new_var <- "0"
2727
mutate_chunk <- function(x) {
28-
print_line <- 19
28+
print_line <- 17
2929
file_text <- readLines("resources/eng-reticulate-cache-test.Rmd")
30-
file_text[print_line] <- paste("print(x + ", x, ")", sep = "")
30+
file_text[print_line] <- paste0("print(x + ", x, ")")
3131
writeLines(file_text, "resources/eng-reticulate-cache-test.Rmd")
3232
}
3333
mutate_chunk(old_var)

0 commit comments

Comments
 (0)