Skip to content

Instantly share code, notes, and snippets.

@HenrikBengtsson
Last active August 9, 2017 14:04
Show Gist options
  • Save HenrikBengtsson/7e454f677bdde2aa0adf775479a7c694 to your computer and use it in GitHub Desktop.
Save HenrikBengtsson/7e454f677bdde2aa0adf775479a7c694 to your computer and use it in GitHub Desktop.
Evaluate unsafe R expression inside Linux container
library("future")
## Launch Linux container rocker/r-base in background
cl <- makeClusterPSOCK("localhost",
rscript = c("docker", "run", "--net=host", "rocker/r-base", "Rscript"),
rscript_args = c("-e", shQuote("install.packages('future')")))
## Evaluate R expression inside container
f <- cluster({ some_unsafe_call() }, workers = cl)
v <- value(f)
## Alternatively, evaluate all future expressions inside the container
plan(cluster, workers = cl)
a %<-% { some_unsafe_call() }
b %<-% { another_unsafe_call() }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment