8

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 sfExports and sfLibrarys, 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.

Claus Wilke
  • 16,992
  • 7
  • 53
  • 104
TheComeOnMan
  • 12,535
  • 8
  • 39
  • 54
  • 3
    System setup, versions, actual code to do those operations? Looks like pkg:snow is not being attached properly. – IRTFM Mar 29 '16 at 13:01
  • 1
    I have snow in the description file and I can see an import(snow) in the namespace. I also added an #' @import snow to the function as well. Is there something else I should be doing? – TheComeOnMan Mar 29 '16 at 13:36
  • 1
    If I explicitly call snow in the wrapper code itself, the package works fine. – TheComeOnMan Mar 29 '16 at 13:39
  • 2
    Was there any solution to this (other than add snow to imports section)? I'm having the same problem. Using Roxygen2 with `importFrom snow setDefaultClusterOptions` but returning same error. – Adrian Jan 23 '17 at 13:31
  • 1
    ... as an aside are you getting more out of `snowfall` than it is costing you? As a usability wrapper I never felt like it improved my experience... but maybe I was already too far down the rabbit hole by the time I stumbled onto it. Unless you have some specialized reasons for wanting to use `snowfall` you may want to consider https://cran.r-project.org/web/packages/future/index.html. It is under active development and the author seems dedicated to supporting a pretty broad variety of backends. – russellpierce Dec 12 '17 at 03:43

2 Answers2

5

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.

russellpierce
  • 4,583
  • 2
  • 32
  • 44
3

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

Thierry
  • 18,049
  • 5
  • 48
  • 66
  • 1
    I have snow in the description file and I can see an import(snow) in the namespace. I also added an #' @import snow to the function as well. Is there something else I should be doing? – TheComeOnMan Mar 29 '16 at 13:37
  • 1
    If I explicitly call snow in the wrapper code itself, the package works fine. – TheComeOnMan Mar 29 '16 at 13:39
  • 3
    I would import only the functions you need for a package rather than importing the entire package. Use `'# @importFrom snow setDefaultClusterOptions` if you use roxygen2 – Thierry Mar 30 '16 at 08:37