It looks like a problem with the area.
Here is my "test suite" that allows me to export various variables or not create df_2 inside a function. I add and remove dumm_df_2 and df_3 outside the function and compare.
library(plyr) library(doParallel) workers=makeCluster(2) registerDoParallel(workers,core=2) plyr_test=function(exportvar,makedf_2) { df_1=data.frame(type=c("a","b"),x=1:2) if(makedf_2){ df_2=data.frame(type=c("a","b"),x=3:4) } print(ls()) ddply(df_1,"type",.parallel=TRUE,.paropts=list(.export=exportvar,.verbose = TRUE),.fun=function(y) { z <- merge(y,df_2,all=FALSE,by="type") }) } ls() rm(df_2,df_3) plyr_test("df_2",T) plyr_test("df_2",F) plyr_test("df_3",T) plyr_test("df_3",F) plyr_test(NULL,T) #ok plyr_test(NULL,F) df_2='hi' ls() plyr_test("df_2",T) #ok plyr_test("df_2",F) plyr_test("df_3",T) plyr_test("df_3",F) plyr_test(NULL,T) #ok plyr_test(NULL,F) df_3 = 'hi' ls() plyr_test("df_2",T) #ok plyr_test("df_2",F) plyr_test("df_3",T) #ok plyr_test("df_3",F) plyr_test(NULL,T) #ok plyr_test(NULL,F) rm(df_2) ls() plyr_test("df_2",T) plyr_test("df_2",F) plyr_test("df_3",T) #ok plyr_test("df_3",F) plyr_test(NULL,T) #ok plyr_test(NULL,F)
I don’t know why, but .export is looking for df_2 in the global environment outside the function (I saw parent.env () in the code, which may be “more correct” than the global environment), while the calculation requires the variable to be found in the same environment as ddply, and automatically exported it.
Using a dummy variable for df_2 outside the function allows .export to work, and the calculation uses df_2 inside.
When .export cannot find the variable outside the function, it returns:
Error in e$fun(obj, substitute(ex), parent.frame(), e$data) : unable to find variable "df_2"
With dm_2 a dummy variable outside the function, but without an internal one, .export is fine, but ddply outputs:
Error in do.ply(i) : task 1 failed - "object 'df_2' not found"
Perhaps, since this is a small example or perhaps not parallelized, it actually runs on a single core and avoids the need to export anything. A larger example might fail without .export, but someone might try this.