I am trying to run code on several cores (I tried both the snow and parallel packages). I have
cl <- makeCluster(2)
y <- 1:1
The nodes don't know about the y in the global environment on the master. You need to tell them somehow.
library(parallel)
cl <- makeCluster(2)
y <- 1:10
# add y to function definition and parSapply call
parSapply(cl, 1:5, function(x,y) x + y, y)
# export y to the global environment of each node
# then call your original code
clusterExport(cl, "y")
parSapply(cl, 1:5, function(x) x + y)