Skip to content

Commit

Permalink
Fix: load package (and cache) of external engine only if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
leogama committed Sep 12, 2022
1 parent 706ab38 commit 4ef42fe
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions R/engine.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ cache_engines$.get = cache_engines$get
cache_engines$get = function(name, ...) {
if (missing(name)) {
cache_engines$.get(...)
} else if (!identical(name, 'python') || !isFALSE(options$python.reticulate)) {
cache_engines$.get(name, ...)
} else {
NULL
cache_importer = cache_engines$.get(name, ...)
cache_importer()
}
}

Expand Down Expand Up @@ -288,6 +287,17 @@ eng_python = function(options) {
}
}

cache_eng_python = function() {
# TODO: change this hack to reticulate::cache_eng_python after
# https://github.com/rstudio/reticulate/pull/1210 is merged and released
if (!isFALSE(options$python.reticulate) &&
'cache_eng_python' %in% ls(asNamespace('reticulate'))) {
getFromNamespace('cache_eng_python', 'reticulate')
} else {
NULL
}
}

## Java
# e.g. see http://cran.rstudio.com/package=jvmr

Expand Down Expand Up @@ -925,11 +935,7 @@ knit_engines$set(
verbatim = eng_verbatim
)

# TODO: change this hack to reticulate::cache_eng_python after
# https://github.com/rstudio/reticulate/pull/1210 is merged and released
if ('cache_eng_python' %in% ls(asNamespace('reticulate'))) {
cache_engines$set(python = getFromNamespace('cache_eng_python', 'reticulate'))
}
cache_engines$set(python = cache_eng_python)

get_engine = function(name) {
fun = knit_engines$get(name)
Expand Down

0 comments on commit 4ef42fe

Please sign in to comment.