Skip to content

Commit ff39889

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

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
@@ -322,18 +322,19 @@ save_python_session <- function(cache_path) {
322322
#' Typically, this will be set within a document's setup chunk, or by the
323323
#' environment requesting that Python chunks be processed by this engine.
324324
#'
325-
#' @param cache_path
326-
#' The path to save the chunk cache, as provided by `knitr` during chunk execution.
325+
#' @param options
326+
#' List of chunk options provided by `knitr` during chunk execution.
327+
#' Contains the caching path.
327328
#'
328329
#' @export
329-
cache_eng_python <- function(cache_path) {
330+
cache_eng_python <- function(options) {
330331
module <- tryCatch(import("dill"), error = identity)
331332
if (inherits(module, "error")) {
332333
if (module$message == "ImportError: No module named dill") return()
333334
stop(module$message)
334335
}
335336

336-
module$load_session(filename = paste0(cache_path, ".pkl"))
337+
module$load_session(filename = paste0(options$hash, ".pkl"))
337338
}
338339

339340

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)