2

I am currently working on a Golem Shiny App called "package_name" (which is a requirement for me) for which some functions I created need to use functions from the {furrr} and {future} packages. However, whenever I try to run them, I get the following error :

Error : there is no package called 'package_name'

Please note that whenever any function that does not use either package works perfectly fine.

Does anyone know what the problem might be ?

Thanks !

  • With parallel codes, you may have to import the packages, objects etc. Without an example code, it is not clear though – akrun Jul 23 '21 at 17:25

1 Answers1

1

While building the application with {golem}, the package with the app is not installed on your machine. When you use {future}, the code is run inside another R session, meaning that the objects are transported and the libraries reloaded.

BUT if you try to use a function from inside your current app into your future, you need to make it "transportable", and using package_name::function() will not work because your package is not installed.

Let's say you need to use current_app_fun(), defined inside your package. Technically, {future} will be able to transport this function, as it uses {globals} to identify the objects to transport to the new R session.

observeEvent( input$bla , {
  # future() will identify that it needs to
  # transport current_app_fun()
  future({
    current_app_fun()
  })
})

You can also do an extra step just to be extra cautious:

observeEvent( input$bla , {
  func_for_future <- current_app_fun
  future({
    func_for_future()
  })
})

Cheers, Colin

Colin FAY
  • 4,849
  • 1
  • 12
  • 29
  • Thank you very much, it is very clear indeed, and it does perfectly solve my issue ! – Henri Freixe Jul 27 '21 at 14:50
  • @HenriFreixe Great! Feel free to accept the answer then :) – Colin FAY Jul 28 '21 at 14:12
  • @ColinFAY this was a great and very elegant solution...cheers! – JJ Fantini Mar 23 '23 at 10:46
  • @ColinFAY thanks for this solution (and for golem!). One issue I have with this solution, however, is that it is cumbersome if you have custom functions that depend on other custom functions. Transporting all of them can be tedious (e.g., I have a data ingestion function that depends on ~7 other utility functions.) Is there a plan to make custom functions in `golem` automatically transportable when using `future` and `promises`? Or perhaps this is not a `golem` issue and cannot be addressed there. – Will Hipson May 02 '23 at 12:49