Greetings,
I am trying to use Reference Class methods in Snowfall, using R 2.12.1
on Ubuntu Natty. Using then directly seems to work (stanza 2 below),
but using them indirectly does not (stanza 3 below). I get an "attempt
to apply non-function" error.
In addition to exporting the instance of the object I created to the
Snowfall slaves, I also made several attempts to export the method
itself (e.g. sfExport("instance$method") or some such), with no
success. Very strangely, if I run Stanza 2 below, then stanza 3 will
work.
I tried emailing the Snowfall author, but have not heard back. Any
help is greatly appreciated!
Henry Bryant
Texas A&M University
library("snowfall")
library("methods")
# set up a simple reference class
calculator <- setRefClass("calculator")
calculator$methods(do_calc = function(x) {print(x*x)})
my_calc <- calculator$new()
wrapper <- function(x) {my_calc$do_calc(x)}
# STANZA 2: use snowfall without wrapper -- WORKING
#sfInit(parallel=TRUE, cpus=2, type="SOCK")
#sfExport("calculator")
#sfExport("my_calc")
#results <- sfLapply(1:10,my_calc$do_calc)
#sfStop()
#print(results)
# STANZA 3: use snowfall with wrapper -- NOT WORKING
# (not working by itself, but does work if the previous stanza is run
first!!)
sfInit(parallel=TRUE, cpus=2, type="SOCK")
sfExport("calculator")
sfExport("my_calc")
sfExport("wrapper")
last_results <- sfLapply(1:10,wrapper)
sfStop()
cat("\nRESULTS FROM SECOND TRY:\n")
print(last_results)
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.