vignettes/util_os.Rmd
util_os.Rmd
The util_os
function returns the operating system of the current R
session.
linux
for GNU/Linux operating systemosx
for Macintosh operating systemwindows
for Windows operating system
library(jeksterslabRutils)
util_os()
#> sysname
#> "linux"
I use the util_os
function to programatically employ forking on operating systems (POSIX) that support it and employ sockets on Windows.
exe <- function(cores = 2) {
os <- jeksterslabRutils::util_os()
cat("Operating System:", os)
if (os %in% c("linux", "osx")) {
return(
parallel::mclapply(
X = 1:5,
FUN = rnorm,
mc.cores = cores
)
)
}
if (os == "windows") {
cl <- parallel::makeCluster(cores)
on.exit(
parallel::stopCluster(cl)
)
return(
parallel::parLapply(
X = 1:5,
fun = rnorm
)
)
}
}
exe()