Skip to content

Commit

Permalink
Force argument in function environment
Browse files Browse the repository at this point in the history
- correct object export discussed in
  <#241 (comment)>
  • Loading branch information
Jiefei-Wang authored and mtmorgan committed Mar 28, 2023
1 parent b309acd commit a96874a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions R/bpvalidate.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ setMethod("show", "BPValidate", function(object) {
i <- vapply(unknown, function(x) {
!exists(x, envir = env, inherits = FALSE)
}, logical(1))
## Force evaluation of the known arguments to
## make sure they will be exported correctly
known <- unknown[-i]
for(nm in known) force(env[[nm]])
unknown <- unknown[i]
env <- parent.env(env)
}
Expand Down
11 changes: 11 additions & 0 deletions inst/unitTests/test_bpexportglobals.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,14 @@ test_bpexportglobals_bplapply <- function()
current <- bplapply(1:2, function(i) getOption("BAR"), BPPARAM=param)
checkIdentical("baz", unique(unlist(current)))
}

test_bpexportglobals_lazyEvaluation <- function(){
foo <- function(k){
param <- SnowParam(2L, exportglobals=TRUE)
bplapply(1:2, function(x){
k
}, BPPARAM = param)
}
k <- 1
checkIdentical(foo(k), list(1, 1))
}

0 comments on commit a96874a

Please sign in to comment.