[R] file connection when using parallel
Arnaud Mosnier
a.mosnier at gmail.com
Tue May 24 18:01:27 CEST 2016
Dear UserRs,
I have a little problem creating a file connection when working in parallel
(see the reproducable script below).
I am sure this is something obvious,
Can you enlighten me ?
Thanks,
Arnaud
# This part works
#----------------
cat("This is a test file" , file={f <- tempfile()})
con <- file(f, "rt")
# Doing what I think is the same thing gives an error message when executed
in parallel
#--------------------------------------------------------------------------------------
library(parallel)
cl <- makeCluster(2)
## Exporting the object f into the cluster
clusterExport(cl, "f")
clusterEvalQ(cl[1], con <- file(f[[1]], "rt"))
#Error in checkForRemoteErrors(lapply(cl, recvResult)) :
# one node produced an error: cannot open the connection
## Creating the object f into the cluster
clusterEvalQ(cl[1],cat("This is a test file" , file={f <- tempfile()}))
clusterEvalQ(cl[1],con <- file(f, "rt"))
#Error in checkForRemoteErrors(lapply(cl, recvResult)) :
# one node produced an error: cannot open the connection
[[alternative HTML version deleted]]
More information about the R-help
mailing list