Search code examples
rparallel-processingdplyrfuturestatic-code-analysis

Suppress static code inspection in R (future package)


I have a long calculation which I am trying to parallelize using future package (specifically within an R shiny application).

I have used dplyr package for all data manipulations and there are a lot of column names that are not referred with quotation marks. When I try to run this function that I know to be working when non parallelized, I get the following error:

Warning: Error in : Identified global objects via static code inspection ({if (i > maxProgress) {; maxProgress <- i; shinyWidgets::updateProgressBar(session = session, id = "pb",; value = 100 * i/length(scanList)); ...; }; return(resultInstance); }). Failed to locate global object in the relevant environments: ‘Months in Service’

because static code inspection thinks ‘Months in Service’ is a global variable and fails to find it (it is in fact a column name of a dplyr tibble), so it never runs my code.

If I do the following globally before calling the function:

`Months in Service` <- NULL

it gives the same error for another column name. So one solution is to define each of those names as global variables and hope dplyr will work the same. However is there another simple way to get around this such as telling R to evaluate everything as it would have done without parallelization (each iteration is completely independent)

Edit 1: I simplified the operation and tested if NULL would actually work. It doesnt, it would complain because it thinks column name is NULL, for example:

no applicable method for 'rename_' applied to an object of class "NULL"

Edit 2: example reproduction

 library("dplyr")
 library("listenv")

  exampleTibb <- tibble(`col 1`=c(1,2,3))
  exampleFuture <- listenv()
  exampleFuture[[1]] %<-% future({ rename(exampleTibb, `col 2` = `col 1`) })
  exampleFuture <- as.list(exampleFuture)

Solution

  • Author of the future package here: This is due to a bug that has been fixed for future 1.8.0. I'm preparing to submit this to CRAN, but in the meanwhile you can either do:

    options(future.globals.onMissing = "ignore")
    

    or, better, install the develop version:

    remotes::install_github("HenrikBengtsson/future@develop")
    

    UPDATE 2018-04-08: future 1.8.0 is now on CRAN.


    UPDATE 2018-04-07: This error only occurs when using nested futures. Note that you introduce nested futures by mistake when you use both %<-% and future(). That is a clearly a mistake. You want to use, either:

    exampleFuture[[1]] %<-% { rename(exampleTibb, `col 2` = `col 1`) }
    

    or

    exampleFuture[[1]] <- future({ rename(exampleTibb, `col 2` = `col 1`) })
    

    and certainly not both.