background-methods: Functions for backgrounding calculations

Description Usage Arguments Details Value Author(s) Examples

Description

Perform calculations concurently in the background thereby freeing the R console to perform other tasks. The package currently supports a sequential backend, where the calculation is evaluted when it is brought into the foreground along with a multicore backend, where the calculation is started immediately after it is backgrounded. Other packages, such as multicore.background can be used for true process backgrounding.

Usage

1
2
3
4
5
6
register.background(backendName=NULL)
bg(expr, par.gen=options()$background.backend)
done(process)
fg(process)
kill(process)
killed(process)

Arguments

backendName

The name of the reference class backgrounding the calculations

expr

The expression to be calculated in the background

par.gen

An object inherited from bg.interface that provides the concurrent backend

process

The backgrounded process returned from the bg function

Details

The bg function is used to background a calculation. After a calculation is backgrounded, the done function allows a user to find out if the calculation is complete. The fg function allows a user to retrieve the result of the calculation. If the fg function is called before the calculation is complete, then the R session will block until it is complete and then the result is returned. The kill function allows a user to kill a backgrounded calculation and the killed function checks to see if a running calculation has been killed.

Value

bg returns a handle to the backgrounded calculation which can then be used as an argument to done or fg.

done returns TRUE or FALSE depending on whether or not the backgrounded calculation is complete.

fg returns the result of the backgrounded calculation.

kill returns TRUE.

killed returns TRUE if the calculation has been killed, FALSE otherwise.

Author(s)

Michael Kane

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# Background a simple R expression.
bg.comp <- bg({Sys.sleep(2); "Awake!\n"})

# If the calculation is not complete do something else.
if (!done(bg.comp)) {
  cat("Waiting for calculation\n")
}

# Output the result.
cat(fg(bg.comp))

background documentation built on May 2, 2019, 5:23 p.m.