I'm developing an R package which needs to use parallelisation as made available by the snowfall
package. snowfall
doesn't seem to import the same was as other packages like ggplot2
, data.table
, etc. I've included snowfall
, rlecuyer
, and snow
in the description file, name space file, and as an import argument in the function itself. When I try to access this function, I get the following error:
Error in sfInit() : could not find function "setDefaultClusterOptions"
The sfInit
function seems to have a nostart
/ nostop
argument which it says is related to nested usage of sfInit
but that doesn't seem to do the trick for me either.
The actual code itself uses an sfInit
(which is where I get the error), some sfExport
s and sfLibrary
s, and an sfLapply
.
Possible solution:
It seems to work if I move snow
from the import section to the depends section in the Desciption file. I don't know why though.
When you include a package in 'Depends' when one attaches your package they also attach the package on which your package Depends to their namespace.
This and other differences between Depends and Imports is explained well in other questions on this site.
If you look at {snowfall}'s DESCRIPTION you'll see that it Depends on {snow}
. It is plausible that the authors of snowfall know something we don't and that {snow}
has to be attached to the global search path in order to work. In fact that is the top caveat in the top answer to the question I linked above...
... if your package relies on a package A which itself "Depends" on another package B, your package will likely need to attach A with a "Depends directive.
This is because the functions in package A were written with the expectation that package B and its functions would be attached to the search() path.
So, in your case, it just so happens that all {snowfall}
wants is {snow}
and you happened to provide it. However, it appears the more correct behavior may be for you to Depend on {snowfall}
directly.
setDefaultClusterOptions
is a function from the snow
package. You need to import that too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With