R/I_forceEval.R

Defines functions .forceEval

# Forces evaluation of objects with names in "toForce" from "envir" enviroment to "cluster".
# If ALL == TRUE it evaluates all the objects in "envir"

.forceEval <- function(toForce = c(), envir = parent.frame(), ALL = FALSE)
{
  allNames <- toForce
  
  if(ALL) allNames <- c(allNames, ls(envir = envir))
  
  lapply(allNames, function(input) force(get(input, envir = envir)) )
  
  return( NULL )
}


# Test

# f <- function(x, y){ function() c(x, y) }
# lf <- vector("list", 5)
# for (i in seq_along(lf)) lf[[i]] <- f(i, i)
# lf[[1]]()  # returns 5, 5 which is wrong
# 
# f <- function(x, y){ .forceEval(c("x", "y")); function() c(x, y) }
# lf <- vector("list", 5)
# for (i in seq_along(lf)) lf[[i]] <- f(i, i)
# lf[[1]]()  # returns 1, 1 which right

Try the synlik package in your browser

Any scripts or data that you put into this service are public.

synlik documentation built on March 7, 2023, 8:39 p.m.