Skip to content

Commit f30a3c2

Browse files
Memoize addCovrLibPath()
1 parent e7c8531 commit f30a3c2

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

R/backend_api-ClusterRegistry.R

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,27 @@ ClusterRegistry <- local({
5959

6060

6161
#' @importFrom parallel clusterCall
62-
addCovrLibPath <- function(cl) {
63-
if (!is.element("covr", loadedNamespaces())) return(cl)
64-
debug <- isTRUE(getOption("future.debug"))
62+
addCovrLibPath <- local({
63+
is_covr <- NULL
6564

66-
## WORKAROUND: When running covr::package_coverage(), the
67-
## package being tested may actually not be installed in
68-
## library path used by covr. We here add that path iff
69-
## covr is being used. /HB 2016-01-15
70-
if (debug) mdebug("covr::package_coverage() workaround ...")
71-
libPath <- .libPaths()[1]
72-
clusterCall(cl, fun = function() .libPaths(c(libPath, .libPaths())))
73-
if (debug) mdebug("covr::package_coverage() workaround ... DONE")
74-
75-
cl
76-
}
65+
function(cl) {
66+
if (!is.null(is_covr)) {
67+
if (!is_covr) return(cl)
68+
} else {
69+
is_covr <<- is.element("covr", loadedNamespaces())
70+
if (!is_covr) return(cl)
71+
}
72+
debug <- isTRUE(getOption("future.debug"))
73+
74+
## WORKAROUND: When running covr::package_coverage(), the
75+
## package being tested may actually not be installed in
76+
## library path used by covr. We here add that path iff
77+
## covr is being used. /HB 2016-01-15
78+
if (debug) mdebug("covr::package_coverage() workaround ...")
79+
libPath <- .libPaths()[1]
80+
clusterCall(cl, fun = function() .libPaths(c(libPath, .libPaths())))
81+
if (debug) mdebug("covr::package_coverage() workaround ... DONE")
82+
83+
cl
84+
}
85+
})

0 commit comments

Comments
 (0)