beauchamplab / rave

For all RAVE info, including installation instructions, visit
https://beauchamplab.github.io/rave
23 stars 5 forks source link

Future package inaccurate capturing of environment names #8

Closed dipterix closed 5 years ago

dipterix commented 5 years ago

When loading data with future package, it pops out the following error message

Error in vapply(where, FUN = envname, FUN.VALUE = NA_character_, USE.NAMES = FALSE) : 
  values must be length 1,
 but FUN(X[[12]]) result is length 18

It seems that future package is not detecting variables correctly.

dipterix commented 5 years ago

This rarely happens. When debuging with RStudio, it tells me the following code in future package (1.9.0) throws error:

> if (name == "") {
>   name <- capture.output(print(env))
>   name <- gsub("(.*: |>)", "", name)
> }
> name 

Basically future package will automatically detect variables that are needed and fork them to another process. The way to find environment is implemented in a bad way:

  1. It first try to look if the variable is in a package environment, if yes, get package environment (this is OK)
  2. If the environment is not a package environment, it then tries to print the environment. Yes, that's right, print the environment, hoping that the environment returns its name (such as base for base environment), or memory address (something like 0x12345678).

The step 2 is really badly implemented. For example if the environment has print function overridden, like R6 class with customized print method, then this piece of code will fail.

As a compromise, I'll change all the print method from R6 class in rave to

...
print = function(...){
  pryr::address(self)
},
info = function(){
  ... # my original print body
},
...

so that future will detect the environment correctly, and implement info method to print class definitions.

dipterix commented 5 years ago

I contacted the original author of future. This issue should be solved