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 82b7930
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions R/engine.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ 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 if (!is.null(cache_importer <- cache_engines$.get(name, ...))) {
cache_importer()
} else {
NULL
}
Expand Down Expand Up @@ -288,6 +288,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 +936,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 82b7930

Please sign in to comment.