R foreach loop - package load fails -


i'm unable load packages parallel processes in foreach %dopar% loop.

i create 4 sock clusters using foreach , dosnow packages, try run trivial parallel process. works %dopar% without using packages, loading arbitrary package throws error.

sample code below, followed session info showing packages in use.

i have used type of code before without issues. recent network changes @ company meant had change settings (default library path, etc), may related change. not sure start in troubleshooting issue - appreciated!

#load foreach , dosnow packages, setup 4 clusters#  > require(foreach)  > require(dosnow)  > registerdosnow(makecluster(4, type = "sock"))  > getdoparworkers() [1] 4  > getdoparname() [1] "dosnow"  # %dopar% loop without loading packages -- works ok #  > foreach(i=1:2) %dopar%  {     i+1 }  [[1]] [1] 2  [[2]] [1] 3  # %dopar% loop loading package -- not work #  > foreach(i=1:2,.packages="forecast") %dopar%    {        i+1    }  error in e$fun(obj, substitute(ex), parent.frame(), e$data) :    worker initialization failed: package or namespace load failed        'forecast' 

session info: r version 3.2.1 (2015-06-18) platform: x86_64-w64-mingw32/x64 (64-bit) running under: windows 7 x64 (build 7601) service pack 1

locale: [1] lc_collate=english_united states.1252 lc_ctype=english_united states.1252 lc_monetary=english_united states.1252 lc_numeric=c
[5] lc_time=english_united states.1252

attached base packages: [1] stats graphics grdevices utils datasets methods base

other attached packages: [1] writexls_3.6.1 rlist_0.4 timeseries_3012.99 reshape2_1.4.1 plyr_1.8.3 lubridate_1.3.3 lmtest_0.9-34 lattice_0.20-31 knitr_1.10.5
[10] hts_4.5 matrix_1.2-1 sparsem_1.6 ggplot2_1.0.1 data.table_1.9.4 car_2.0-25 forecast_6.1 timedate_3012.100 zoo_1.7-12
[19] dosnow_1.0.12 snow_0.3-13 iterators_1.0.7 foreach_1.4.2

loaded via namespace (and not attached): [1] rcpp_0.11.6 compiler_3.2.1 nloptr_1.0.4 tseries_0.10-34 tools_3.2.1 lme4_1.1-8 digest_0.6.8 memoise_0.2.1 gtable_0.1.2 nlme_3.1-120
[11] mgcv_1.8-6 parallel_3.2.1 proto_0.3-10 stringr_1.0.0 grid_3.2.1 nnet_7.3-9 minqa_1.2.4 magrittr_1.5 scales_0.2.5 codetools_0.2-11 [21] mass_7.3-40 splines_3.2.1 pbkrtest_0.4-2 colorspace_1.2-6 fracdiff_1.4-2 quantreg_5.11 quadprog_1.5-5 stringi_0.5-5 munsell_0.4.2 chron_2.3-47

other info may useful- .libpaths() location , details makecluster function.

> .libpaths()  [1] "c:/users/g082580/documents/my documents/r/r-3.2.1" "c:/r-3.2.1/library"                                 > makecluster(4,type="sock",manual=true) 

manually start worker on localhost c:/r-32~1.1/bin/rscript.exe "c:/users/g082580/documents/my documents/r/r-3.2.1/snow/rsocknode.r" master=localhost port=11535 out=/dev/null snowlib=c:/users/g082580/documents/my documents/r/r-3.2.1

if need use .libpaths function in order load packages on master, you'll need call on workers well. example uses clustercall function initialize workers same master:

library(dosnow) cl <- makesockcluster(4) registerdosnow(cl) clustercall(cl, function(x) .libpaths(x), .libpaths()) 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -