Import snowfall into custom package R

I am developing an R package that should use the parallelization provided by the snowfall package. snowfall doesn't seem to import the same as other packages like ggplot2 , data.table , etc. I included rlecuyer , rlecuyer and snow in the description file, the namespace 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"

It seems that the sfInit function has a nostart / nostop , which he says is related to the nested use of sfInit , but this does not seem to do the trick for me.

The actual code itself uses sfInit (where I get the error), some sfExport and sfLibrary s, and sfLapply .

Possible solution: It seems to work if I move snow from the import section to the dependency section in the Desciption file. However, I do not know why.

+7
r snowfall
source share
2 answers

When you include a package in Dependencies, when you attach your package, they also attach the package on which your package depends on their namespace.

These and other differences between Depends and Imports are well explained in other issues on this site.

If you look at {snowfall} DESCRIPTION, you will see that it depends on {snow} . It is plausible that the authors of snowfall know something that we don’t have, and that {snow} must be tied to the global search path in order to work. In fact, this is the upper clause in the upper answer to the question that I linked above ...

... if your package uses package A, which itself "depends" on another package B, your package will probably need to connect A using "Depends on the directive.

This is because the functions in package A were written using the expectation that package B and its functions would be attached to search ().

So, in your case, it happens that everyone {snowfall} wants {snow} , and you succeeded. However, it seems that the more appropriate behavior may be for you directly on {snowfall} .

+3
source share

setDefaultClusterOptions is a function from the snow package. You need to import too.

+2
source share

All Articles