cl <- default_cluster()
cluster_assign(cl, a = runif(1))
cluster_call(cl, a)
# Assign different values on each cluster
cluster_assign_each(cl, b = c(1, 10))
cluster_call(cl, b)
# Partition a vector so that each worker gets approximately the
# same amount of it
cluster_assign_partition(cl, c = 1:11)
cluster_call(cl, c)
# If you want different to compute different values on each
# worker, use `cluster_call()` directly:
cluster_call(cl, d <- runif(1))
cluster_call(cl, d)
# cluster_copy() is a useful shortcut
e <- 10
cluster_copy(cl, "e")
cluster_call(cl, ls())
cluster_rm(cl, letters[1:5])
cluster_call(cl, ls())
# Use cluster_library() to load packages
cluster_call(cl, search())
cluster_library(cl, "magrittr")
cluster_call(cl, search())
Run the code above in your browser using DataLab