The hardware and bandwidth for this mirror is donated by dogado GmbH, the Webhosting and Full Service-Cloud Provider. Check out our Wordpress Tutorial.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]dogado.de.
foreach
🔌 parabar
The doParabar
package acts as a foreach
parallel adaptor for parabar
backends. It provides a minimal implementation for the
foreach::%dopar%
operator, enabling seamless integration of
the parabar
package with the foreach
package.
You can install doParabar
directly from
CRAN
using the following command:
# Install the package from `CRAN`.
install.packages("doParabar")
Alternatively, you can also install the latest development version
from GitHub
via:
# Install the package from `GitHub`.
::install_github("mihaiconstantin/doParabar") remotes
Then, load the package as usual using the library
function:
# Load the package.
library(doParabar)
Note. By default, and for various reasons,
the doParabar
package does not automatically load other
packages. Instead, it is recommended to load the foreach
and parabar
packages explicitly in your scripts (i.e., or add them to your
Imports
in the DESCRIPTION
file when
developing an R
package).
# Load the `foreach` package.
library(foreach)
# Load the `parabar` package.
library(parabar)
Note. Should you need to suppress the
package startup messages (e.g., from the parabar
package) you can use the suppressPackageStartupMessages
function (e.g.,
suppressPackageStartupMessages(parabar)
).
Below you can find a minimal example of how to use
doParabar
and parabar
packages in your R
scripts. All examples below assume that
you have already installed and loaded the packages.
[!TIP] For a more detailed discussion see the vignette “Using
parabar
withforeach
”.
# Create an asynchronous `parabar` backend.
<- start_backend(cores = 2, cluster_type = "psock", backend_type = "async")
backend
# Register the backend with the `foreach` package for the `%dopar%` operator.
registerDoParabar(backend)
# Get the parallel backend name.
getDoParName()
# Check that the parallel backend has been registered.
getDoParRegistered()
# Get the current version of backend registration.
getDoParVersion()
# Get the number of cores used by the backend.
getDoParWorkers()
# Define some variables strangers to the backend.
<- 10
x <- 100
y <- "Not to be exported."
z
# Used the registered backend to run a task in parallel via `foreach`.
<- foreach(i = 1:300, .export = c("x", "y"), .combine = c) %dopar% {
results # Sleep a bit.
Sys.sleep(0.01)
# Compute and return.
+ x + y
i
}
# Show a few results.
head(results, n = 10)
tail(results, n = 10)
# Verify that the variable `z` was not exported.
try(evaluate(backend, z))
# To make packages available on the backend, see the `.packages` argument.
# Stop the backend.
stop_backend(backend)
[!NOTE] The
doParabar
package provides only a minimal implementation for theforeach::%dopar%
operator. If you need additional functionality, please consider contributing to the package, or opening an issue onGitHub
.
GitHub
.GitHub
.
The
parabar
and doParabar
documentation,
vignettes, and other website materials by
Mihai
Constantin are licensed under
CC
BY 4.0
.
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.
Health stats visible at Monitor.