#' Automatically set `mode` and `cpus` for `parallelStart`
#' given the operating system
#' @param flag logical indicating if to use parallelization or not
#' @param cpus number of cpus to use
#' @param ... additional parameters for `parallelStart`
#' @export
parallelStartAuto = function(flag = FALSE, cpus = NA_integer_, ...) {
os = .Platform$OS.type
if ( isTRUE(flag) ) {
mode = switch(os,
unix = 'multicore',
windows = 'socket')
} else if ( isFALSE(flag) ) {
mode = 'local'
if ( !is.na(cpus) ) {
warning('setting cpus = NA')
}
cpus = NA_integer_
} else {
stop('invalid flag')
}
if ( (mode == 'local') && !is.na(cpus) ) {
stop('invalid value for `cpus`')
}
parallelMap::parallelStart(mode, cpus, ...)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.