Why am I getting the error "Error: there is no package called 'MyPackage'" when using future.apply

123 views Asked by At

I am creating a package 'MyPackage' which makes use of future.apply. When I attempt to use the function future_lapply() I get an error "Error: there is no package called 'MyPackage'". This happens even on the most minimal example: future.apply::future_lapply(1:8,function(x){x}).

I have previously also had similar errors claiming a function did not exists, despite being successfully called elsewhere.

I am on windows and thus using plan(multisession). I am using the devtools ecosystem for developing my package.

1

There are 1 answers

1
littlefeltfangs On

tl;dr - don't use devtools::load_all() and future::multisession.

This is likely caused by an interaction between multisession and load_all().

The devtools::load_all() function simulates the installation and loading of your package, which is great for development, but doesn't actually install it. This means if you were to close and reopen R, using library(MyPackage) wouldn't load your current development version. If you have previously install a version of your package through other methods it would instead load that.

When using future::multisession you are essentially letting future to open fresh R sessions, and then run code in these. Future manages what needs to be loaded into these sessions behind the scenes, but will use the version of your package that you have installed not the one you have loaded with load_all(). This will result in your no package error in the case of the package not being installed at all, or might result in other errors depending on incompatibilities between your installed package version and your development version.

When using future (and probably other packages like it), you'll want to make sure you are fully installing the version of the package you are wanting to test.