knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
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 systemlibrary(jeksterslabRutils) util_os()
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()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.