TimTeaFan / dplyover

Create columns by applying functions to vectors and/or columns in 'dplyr'.
https://timteafan.github.io/dplyover/
Other
60 stars 1 forks source link

subscript out of bounds error in README examples on WIndows #3

Closed brshallo closed 3 years ago

brshallo commented 3 years ago

Just installed and was unable to run through README example on a windows machine. When I run on linux (via Rstudio Cloud) worked fine.

Error occurs during meta_setup() step.

library(dplyr)
library(dplyover)

tibble(a = 1:25) %>%
  mutate(over(c(1:3),
              list(lag  = ~ lag(a, .x),
                   lead = ~ lead(a, .x)),
              .names = "a_{fn}{x}"))
#> Error: Problem with `mutate()` input `..1`.
#> i `..1 = over(c(1:3), list(lag = ~lag(a, .x), lead = ~lead(a, .x)), .names = "a_{fn}{x}")`.
#> x subscript out of bounds

Created on 2021-05-18 by the reprex package (v2.0.0)

Session info ``` r sessioninfo::session_info() #> - Session info --------------------------------------------------------------- #> setting value #> version R version 3.5.1 (2018-07-02) #> os Windows 10 x64 #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate English_United States.1252 #> ctype English_United States.1252 #> tz America/New_York #> date 2021-05-18 #> #> - Packages ------------------------------------------------------------------- #> package * version date lib source #> assertthat 0.2.1 2019-03-21 [1] CRAN (R 3.5.3) #> backports 1.2.1 2020-12-09 [1] CRAN (R 3.5.1) #> cli 2.5.0 2021-04-26 [1] CRAN (R 3.5.1) #> crayon 1.4.1 2021-02-08 [1] CRAN (R 3.5.1) #> DBI 1.1.1 2021-01-15 [1] CRAN (R 3.5.1) #> digest 0.6.27 2020-10-24 [1] CRAN (R 3.5.1) #> dplyover * 0.0.8.9000 2021-05-18 [1] Github (TimTeaFan/dplyover@ef2b0a5) #> dplyr * 1.0.6 2021-05-05 [1] CRAN (R 3.5.1) #> ellipsis 0.3.2 2021-04-29 [1] CRAN (R 3.5.1) #> evaluate 0.14 2019-05-28 [1] CRAN (R 3.5.3) #> fansi 0.4.2 2021-01-15 [1] CRAN (R 3.5.1) #> fs 1.5.0 2020-07-31 [1] CRAN (R 3.5.1) #> generics 0.1.0 2020-10-31 [1] CRAN (R 3.5.1) #> glue 1.4.2 2020-08-27 [1] CRAN (R 3.5.1) #> highr 0.9 2021-04-16 [1] CRAN (R 3.5.1) #> htmltools 0.5.1.1 2021-01-22 [1] CRAN (R 3.5.1) #> knitr 1.33 2021-04-24 [1] CRAN (R 3.5.1) #> lifecycle 1.0.0 2021-02-15 [1] CRAN (R 3.5.1) #> magrittr 2.0.1 2020-11-17 [1] CRAN (R 3.5.1) #> pillar 1.6.1 2021-05-16 [1] CRAN (R 3.5.1) #> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 3.5.3) #> purrr 0.3.4 2020-04-17 [1] CRAN (R 3.5.3) #> R6 2.5.0 2020-10-28 [1] CRAN (R 3.5.1) #> reprex 2.0.0 2021-04-02 [1] CRAN (R 3.5.1) #> rlang 0.4.11 2021-04-30 [1] CRAN (R 3.5.1) #> rmarkdown 2.7 2021-02-19 [1] CRAN (R 3.5.1) #> rstudioapi 0.13 2020-11-12 [1] CRAN (R 3.5.1) #> sessioninfo 1.1.1 2018-11-05 [1] CRAN (R 3.5.2) #> stringi 1.5.3 2020-09-09 [1] CRAN (R 3.5.1) #> stringr 1.4.0 2019-02-10 [1] CRAN (R 3.5.3) #> styler 1.4.0 2021-03-22 [1] CRAN (R 3.5.1) #> tibble 3.1.2 2021-05-16 [1] CRAN (R 3.5.1) #> tidyselect 1.1.1 2021-04-30 [1] CRAN (R 3.5.1) #> utf8 1.2.1 2021-03-12 [1] CRAN (R 3.5.1) #> vctrs 0.3.8 2021-04-29 [1] CRAN (R 3.5.1) #> withr 2.4.2 2021-04-18 [1] CRAN (R 3.5.1) #> xfun 0.22 2021-03-11 [1] CRAN (R 3.5.1) #> yaml 2.2.1 2020-02-01 [1] CRAN (R 3.5.3) #> #> [1] C:/Users/BSHALLOW/Documents/R/win-library/3.5 #> [2] C:/Program Files/R/R-3.5.1/library ```
TimTeaFan commented 3 years ago

Thanks for posting this. This will take me a while to track this down, since I'm not able to reproduce the error. I build this package on a Mac and tested it with my work computer which runs on Windows and I have no problems. Also the checks via Github Action did not fail so far. It is either a problem of the R version or a problem a package version. I run tests on dplyr 1.0.6 and it works fine on Mac and Windows with R 4.0.

It would be great to know at what exact line meta_setup is failing.

I will try to switch to the more thorough RMD Check via Github Actions which also tests older R versions.

brshallo commented 3 years ago

When going through this example:

# dplyover is an extention of dplyr on won't work without it
library(dplyr)
library(dplyover)

# For better printing:
iris <- as_tibble(iris)

# step into debugger
debugonce("over")

tibble(a = 1:25) %>%
  mutate(over(c(1:3),
              list(lag  = ~ lag(a, .x),
                   lead = ~ lead(a, .x)),
              .names = "a_{fn}{x}"))

And then from debugger stepping into meta_setup() the error happens at this line:

par_frame[[".__dplyover_setup__."]][[call_id]][["setup"]] <- setup <- do.call(setup_fn, dots)
#> Error in `*tmp*`[[call_id]] : subscript out of bounds

Specifically when indexing on call_id , e.g. if just evaluate up to there:

par_frame[[".__dplyover_setup__."]][[call_id]]
#> Error in par_frame[[".__dplyover_setup__."]][[call_id]] : 
#>   subscript out of bounds

At this step call_id is equal to "call1":

call_id
#> [1] "call1"

However this is not one of the names in par_frame[[".__dplyover_setup__."]] :

str(par_frame[[".__dplyover_setup__."]])
#>  Named chr [1:2] "1" ...
#>  - attr(*, "names")= chr [1:2] "call_his" "call_lang"

Hence subscript out of bounds error.

TimTeaFan commented 3 years ago

Thanks for adding this information. I still have problems to understand why this error occurs only under a certain R or package versions.

Hopefully issue #7 will solve this bug.

Holer90 commented 3 years ago

I have the exact same issue for all README examples, and I'm running Linux. (As you already figured out) it appears to be an issue with the R version.

Session info:

> session_info()
─ Session info ───────────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 3.6.3 (2020-02-29)
 os       Linux Mint 20.1             
 system   x86_64, linux-gnu           
 ui       RStudio                     
 language en_US:en                    
 collate  en_US.UTF-8                 
 ctype    en_US.UTF-8                 
 tz       Europe/Copenhagen           
 date     2021-06-03                  

─ Packages ───────────────────────────────────────────────────────────────────────
 package     * version    date       lib source                             
 assertthat    0.2.1      2019-03-21 [1] CRAN (R 3.6.3)                     
 backports     1.2.1      2020-12-09 [1] CRAN (R 3.6.3)                     
 callr         3.7.0      2021-04-20 [1] CRAN (R 3.6.3)                     
 cli           2.5.0      2021-04-26 [1] CRAN (R 3.6.3)                     
 crayon        1.4.1      2021-02-08 [1] CRAN (R 3.6.3)                     
 curl          4.3        2019-12-02 [3] CRAN (R 3.6.1)                     
 DBI           1.1.1      2021-01-15 [1] CRAN (R 3.6.3)                     
 dplyover    * 0.0.8.9000 2021-06-03 [1] Github (TimTeaFan/dplyover@ef2b0a5)
 dplyr       * 1.0.6      2021-05-05 [1] CRAN (R 3.6.3)                     
 ellipsis      0.3.2      2021-04-29 [1] CRAN (R 3.6.3)                     
 fansi         0.5.0      2021-05-25 [1] CRAN (R 3.6.3)                     
 generics      0.1.0      2020-10-31 [1] CRAN (R 3.6.3)                     
 glue          1.4.2      2020-08-27 [1] CRAN (R 3.6.3)                     
 lifecycle     1.0.0      2021-02-15 [1] CRAN (R 3.6.3)                     
 magrittr      2.0.1      2020-11-17 [1] CRAN (R 3.6.3)                     
 pillar        1.6.1      2021-05-16 [1] CRAN (R 3.6.3)                     
 pkgbuild      1.0.6      2019-10-09 [3] CRAN (R 3.6.1)                     
 pkgconfig     2.0.3      2019-09-22 [1] CRAN (R 3.6.3)                     
 prettyunits   1.1.1      2020-01-24 [1] CRAN (R 3.6.3)                     
 processx      3.5.2      2021-04-30 [1] CRAN (R 3.6.3)                     
 ps            1.6.0      2021-02-28 [1] CRAN (R 3.6.3)                     
 purrr         0.3.4      2020-04-17 [1] CRAN (R 3.6.3)                     
 R6            2.5.0      2020-10-28 [1] CRAN (R 3.6.3)                     
 remotes       2.4.0      2021-06-02 [1] CRAN (R 3.6.3)                     
 rlang         0.4.11     2021-04-30 [1] CRAN (R 3.6.3)                     
 rprojroot     1.3-2      2018-01-03 [3] CRAN (R 3.5.0)                     
 rstudioapi    0.13       2020-11-12 [1] CRAN (R 3.6.3)                     
 sessioninfo * 1.1.1      2018-11-05 [3] CRAN (R 3.5.1)                     
 tibble        3.1.2      2021-05-16 [1] CRAN (R 3.6.3)                     
 tidyselect    1.1.1      2021-04-30 [1] CRAN (R 3.6.3)                     
 utf8          1.2.1      2021-03-12 [1] CRAN (R 3.6.3)                     
 vctrs         0.3.8      2021-04-29 [1] CRAN (R 3.6.3)                     
 withr         2.4.2      2021-04-18 [1] CRAN (R 3.6.3)                     

[1] /home/tho/R/x86_64-pc-linux-gnu-library/3.6
[2] /usr/local/lib/R/site-library
[3] /usr/lib/R/site-library
[4] /usr/lib/R/library
TimTeaFan commented 3 years ago

I now installed an older version of R to see what's what and I think I found the bug which was at the root of all this. This hotfix should close the issue.

@Holer90 & @brshallo: It would be great if you could confirm.

brshallo commented 3 years ago

Just ran through it, worked for me!

sessioninfo::session_info()
#> - Session info ---------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.5.1 (2018-07-02)
#>  os       Windows 10 x64              
#>  system   x86_64, mingw32             
#>  ui       RTerm                       
#>  language (EN)                        
#>  collate  English_United States.1252  
#>  ctype    English_United States.1252  
#>  tz       America/New_York            
#>  date     2021-06-04                  
#> 
#> - Packages -------------------------------------------------------------------
#>  package     * version date       lib source        
#>  backports     1.2.1   2020-12-09 [1] CRAN (R 3.5.1)
#>  cli           2.5.0   2021-04-26 [1] CRAN (R 3.5.1)
#>  crayon        1.4.1   2021-02-08 [1] CRAN (R 3.5.1)
#>  digest        0.6.27  2020-10-24 [1] CRAN (R 3.5.1)
#>  ellipsis      0.3.2   2021-04-29 [1] CRAN (R 3.5.1)
#>  evaluate      0.14    2019-05-28 [1] CRAN (R 3.5.3)
#>  fansi         0.5.0   2021-05-25 [1] CRAN (R 3.5.1)
#>  fs            1.5.0   2020-07-31 [1] CRAN (R 3.5.1)
#>  glue          1.4.2   2020-08-27 [1] CRAN (R 3.5.1)
#>  highr         0.9     2021-04-16 [1] CRAN (R 3.5.1)
#>  htmltools     0.5.1.1 2021-01-22 [1] CRAN (R 3.5.1)
#>  knitr         1.33    2021-04-24 [1] CRAN (R 3.5.1)
#>  lifecycle     1.0.0   2021-02-15 [1] CRAN (R 3.5.1)
#>  magrittr      2.0.1   2020-11-17 [1] CRAN (R 3.5.1)
#>  pillar        1.6.1   2021-05-16 [1] CRAN (R 3.5.1)
#>  pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 3.5.3)
#>  purrr         0.3.4   2020-04-17 [1] CRAN (R 3.5.3)
#>  reprex        2.0.0   2021-04-02 [1] CRAN (R 3.5.1)
#>  rlang         0.4.11  2021-04-30 [1] CRAN (R 3.5.1)
#>  rmarkdown     2.8     2021-05-07 [1] CRAN (R 3.5.1)
#>  sessioninfo   1.1.1   2018-11-05 [1] CRAN (R 3.5.2)
#>  stringi       1.6.2   2021-05-17 [1] CRAN (R 3.5.1)
#>  stringr       1.4.0   2019-02-10 [1] CRAN (R 3.5.3)
#>  styler        1.4.0   2021-03-22 [1] CRAN (R 3.5.1)
#>  tibble        3.1.2   2021-05-16 [1] CRAN (R 3.5.1)
#>  utf8          1.2.1   2021-03-12 [1] CRAN (R 3.5.1)
#>  vctrs         0.3.8   2021-04-29 [1] CRAN (R 3.5.1)
#>  withr         2.4.2   2021-04-18 [1] CRAN (R 3.5.1)
#>  xfun          0.23    2021-05-15 [1] CRAN (R 3.5.1)
#>  yaml          2.2.1   2020-02-01 [1] CRAN (R 3.5.3)
#> 
#> [1] C:/Users/BSHALLOW/Documents/R/win-library/3.5
#> [2] C:/Program Files/R/R-3.5.1/library
Holer90 commented 3 years ago

I work as intended now. Thanks!

> session_info()
─ Session info ────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value                       
 version  R version 3.6.3 (2020-02-29)
 os       Linux Mint 20.1             
 system   x86_64, linux-gnu           
 ui       RStudio                     
 language en_US:en                    
 collate  en_US.UTF-8                 
 ctype    en_US.UTF-8                 
 tz       Europe/Copenhagen           
 date     2021-06-05                  

─ Packages ────────────────────────────────────────────────────────────────────────────────────────────────────
 package     * version    date       lib source                             
 assertthat    0.2.1      2019-03-21 [1] CRAN (R 3.6.3)                     
 backports     1.2.1      2020-12-09 [1] CRAN (R 3.6.3)                     
 callr         3.7.0      2021-04-20 [1] CRAN (R 3.6.3)                     
 cli           2.5.0      2021-04-26 [1] CRAN (R 3.6.3)                     
 crayon        1.4.1      2021-02-08 [1] CRAN (R 3.6.3)                     
 curl          4.3        2019-12-02 [3] CRAN (R 3.6.1)                     
 DBI           1.1.1      2021-01-15 [1] CRAN (R 3.6.3)                     
 dplyover    * 0.0.8.9000 2021-06-05 [1] Github (TimTeaFan/dplyover@b6a48fb)
 dplyr       * 1.0.6      2021-05-05 [1] CRAN (R 3.6.3)                     
 ellipsis      0.3.2      2021-04-29 [1] CRAN (R 3.6.3)                     
 fansi         0.5.0      2021-05-25 [1] CRAN (R 3.6.3)                     
 generics      0.1.0      2020-10-31 [1] CRAN (R 3.6.3)                     
 glue          1.4.2      2020-08-27 [1] CRAN (R 3.6.3)                     
 lifecycle     1.0.0      2021-02-15 [1] CRAN (R 3.6.3)                     
 magrittr      2.0.1      2020-11-17 [1] CRAN (R 3.6.3)                     
 pillar        1.6.1      2021-05-16 [1] CRAN (R 3.6.3)                     
 pkgbuild      1.0.6      2019-10-09 [3] CRAN (R 3.6.1)                     
 pkgconfig     2.0.3      2019-09-22 [1] CRAN (R 3.6.3)                     
 prettyunits   1.1.1      2020-01-24 [1] CRAN (R 3.6.3)                     
 processx      3.5.2      2021-04-30 [1] CRAN (R 3.6.3)                     
 ps            1.6.0      2021-02-28 [1] CRAN (R 3.6.3)                     
 purrr         0.3.4      2020-04-17 [1] CRAN (R 3.6.3)                     
 R6            2.5.0      2020-10-28 [1] CRAN (R 3.6.3)                     
 remotes     * 2.4.0      2021-06-02 [1] CRAN (R 3.6.3)                     
 rlang         0.4.11     2021-04-30 [1] CRAN (R 3.6.3)                     
 rprojroot     1.3-2      2018-01-03 [3] CRAN (R 3.5.0)                     
 rstudioapi    0.13       2020-11-12 [1] CRAN (R 3.6.3)                     
 sessioninfo * 1.1.1      2018-11-05 [3] CRAN (R 3.5.1)                     
 stringi       1.6.2      2021-05-17 [1] CRAN (R 3.6.3)                     
 stringr       1.4.0      2019-02-10 [1] CRAN (R 3.6.3)                     
 tibble        3.1.2      2021-05-16 [1] CRAN (R 3.6.3)                     
 tidyselect    1.1.1      2021-04-30 [1] CRAN (R 3.6.3)                     
 utf8          1.2.1      2021-03-12 [1] CRAN (R 3.6.3)                     
 vctrs         0.3.8      2021-04-29 [1] CRAN (R 3.6.3)                     
 withr         2.4.2      2021-04-18 [1] CRAN (R 3.6.3)                     

[1] /home/tho/R/x86_64-pc-linux-gnu-library/3.6
[2] /usr/local/lib/R/site-library
[3] /usr/lib/R/site-library
[4] /usr/lib/R/library