Learn R Programming

dMod (version 0.3.1)

runbg: Run an R expression in the background (only on UNIX)

Description

Generate an R code of the expression that is copied via scp to any machine (ssh-key needed). Then collect the results.

Usage

runbg(..., machine = "localhost", filename = NULL, input = ls(.GlobalEnv), compile = FALSE, wait = FALSE)

Arguments

...
Some R code
machine
Character vector, e.g. "localhost" or "knecht1.fdm.uni-freiburg.de" or c(localhost, localhost).
filename
Character, defining the filename of the temporary file. Random file name ist chosen if NULL.
input
Character vector, the objects in the workspace that are stored into an R data file and copied to the remove machine.
compile
Logical. If TRUE, C files are copied and compiled on the remote machine. Otherwise, the .so files are copied.
wait
Logical. Wait until executed. If TRUE, the code checks if the result file is already present in which case it is loaded. If not present, runbg() starts, produces the result and loads it as .runbgOutput directly into the workspace. If wait = FALSE, runbg() starts in the background and the result is only loaded into the workspace when the get() function is called, see Value section.

Value

List of functions check, get() and purge(). check() checks, if the result is ready. get() copies the result file to the working directory and loads it into the workspace as an object called .runbgOutput. This object is a list named according to the machines that contains the results returned by each machine. purge() deletes the temporary folder from the working directory and the remote machines.

Details

runbg() generates a workspace from the input argument and copies the workspace and all C files or .so files to the remote machines via scp. This will only work if *an ssh-key had been generated and added to the authorized keys on the remote machine*. On the remote machine, the script will attempt to load all packages that had been loaded in the local R session. This means that *all loaded packages must be present on the remote machine*. The code snippet, i.e. the ... argument, can include several intermediate results but only the last call which is not redirected into a variable is returned via the variable .runbgOutput, see example below.

Examples

Run this code
## Not run: 
# out_job1 <- runbg({
#          M <- matrix(rnorm(1e2), 10, 10)
#          solve(M)
#          }, machine = c("localhost", "localhost"), filename = "job1")
# out_job1$check()          
# out_job1$get()
# result <- .runbgOutput
# print(result)
# out_job1$purge()
# ## End(Not run)

Run the code above in your browser using DataLab