0

I have an R package and I want to use future to run stuff asynchronously. future is not able to find the functions in my package. This is a known issue in the context of golem apps. I know there is a work-around that involves assigning the functions to the environment in future (see the linked issue), but I'm hoping someone can help me with a function or improvement that will help future find all functions in my package.

Here's a simplified test package illustrating the problem:

My package testpkg has this file structure:

testpkg/
├── DESCRIPTION
├── NAMESPACE
├── R
│   └── do_stuff.R
├── man
│   └── do_stuff.Rd
└── testpkg.Rproj

do_stuff.R is defined as follows:

#' A function that clearly does stuff
#' @export
do_stuff <- function() {
  Sys.sleep(1)
  "Done"
}

Now in an interactive script I try the following:

devtools::load_all()
library(future)
plan(multisession)

val %<-% do_stuff()
val

And the console reads Error: there is no package called ‘testpkg’

Like I said, I know there are workarounds, but in my actual use case I have many functions some of which depend on other custom functions, so it becomes very loopy to assign each and every one of those functions (not to mention data objects). I'd like a way for future to see all functions in my package.

Will Hipson
  • 366
  • 2
  • 9
  • 1
    Have you tried building and installing your package? – mhovd May 18 '23 at 19:47
  • Seems that building and installing it does address the problem. I wonder how this will work in the context of `golem` apps where conventionally you don't build the package. I suppose there's nothing stopping from building the package prior to running the app. Thanks! – Will Hipson May 19 '23 at 11:39
  • 1
    This is because `load_all` only loads in the current environment. – mhovd May 20 '23 at 17:15

0 Answers0