Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

partial() fails with S3 generics on older R versions #647

Closed
ColinFay opened this issue Feb 24, 2019 · 8 comments

Comments

@ColinFay
Copy link
Contributor

commented Feb 24, 2019

I bet this will have the same roots as #629 & #639, but as these two only present compose, I just wanted to share that partial fails with S3 generics:

library(purrr)
packageVersion("purrr")
#> [1] '0.3.0'

map(airquality, mean)
#> $Ozone
#> [1] NA
#> 
#> $Solar.R
#> [1] NA
#> 
#> $Wind
#> [1] 9.957516
#> 
#> $Temp
#> [1] 77.88235
#> 
#> $Month
#> [1] 6.993464
#> 
#> $Day
#> [1] 15.80392

p_mean <- partial(mean, na.rm = TRUE)
p_mean
#> <partialised>
#> function (...) 
#> mean(na.rm = TRUE, ...)
map(airquality, p_mean)
#> Error in UseMethod("mean"): no applicable method for 'mean' applied to an object of class "c('integer', 'numeric')"

Created on 2019-02-24 by the reprex package (v0.2.1)

@ColinFay ColinFay changed the title partial fails with S3 generic partial fails with S3 generics Feb 24, 2019

@elinw

This comment has been minimized.

Copy link

commented Feb 25, 2019

And I'll point out that changing to mean.default solves it. I think it relates to a more general issue around lexical dispatch.

p_mean <- partial(mean.default, na.rm = TRUE)
map(airquality, p_mean)
@yutannihilation

This comment has been minimized.

Copy link
Member

commented Feb 25, 2019

I cannot reproduce this. What's happening...? (edit: included the session info)

library(purrr)

p_mean <- partial(mean, na.rm = TRUE)
p_mean
#> <partialised>
#> function (...) 
#> mean(na.rm = TRUE, ...)

map(airquality, p_mean)
#> $Ozone
#> [1] 42.12931
#> 
#> $Solar.R
#> [1] 185.9315
#> 
#> $Wind
#> [1] 9.957516
#> 
#> $Temp
#> [1] 77.88235
#> 
#> $Month
#> [1] 6.993464
#> 
#> $Day
#> [1] 15.80392

Created on 2019-02-25 by the reprex package (v0.2.1.9000)

Session info
devtools::session_info()
#> ─ Session info ──────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 3.5.2 (2018-12-20)
#>  os       macOS High Sierra 10.13.6   
#>  system   x86_64, darwin15.6.0        
#>  ui       X11                         
#>  language en                          
#>  collate  ja_JP.UTF-8                 
#>  ctype    ja_JP.UTF-8                 
#>  tz       Asia/Tokyo                  
#>  date     2019-02-25                  
#> 
#> ─ Packages ──────────────────────────────────────────────────────────────
#>  package     * version    date       lib source                        
#>  assertthat    0.2.0      2017-04-11 [1] CRAN (R 3.5.0)                
#>  backports     1.1.3      2018-12-14 [1] CRAN (R 3.5.0)                
#>  callr         3.1.1      2018-12-21 [1] CRAN (R 3.5.0)                
#>  cli           1.0.1      2018-09-25 [1] CRAN (R 3.5.0)                
#>  crayon        1.3.4      2017-09-16 [1] CRAN (R 3.5.0)                
#>  desc          1.2.0      2018-05-01 [1] CRAN (R 3.5.0)                
#>  devtools      2.0.1      2018-10-26 [1] CRAN (R 3.5.1)                
#>  digest        0.6.18     2018-10-10 [1] CRAN (R 3.5.1)                
#>  evaluate      0.13       2019-02-12 [1] CRAN (R 3.5.2)                
#>  fs            1.2.6      2018-08-23 [1] CRAN (R 3.5.0)                
#>  glue          1.3.0      2018-07-17 [1] CRAN (R 3.5.1)                
#>  highr         0.7        2018-06-09 [1] CRAN (R 3.5.0)                
#>  htmltools     0.3.6      2017-04-28 [1] CRAN (R 3.5.0)                
#>  knitr         1.21       2018-12-10 [1] CRAN (R 3.5.1)                
#>  magrittr      1.5        2014-11-22 [1] CRAN (R 3.5.0)                
#>  memoise       1.1.0      2017-04-21 [1] CRAN (R 3.5.0)                
#>  pkgbuild      1.0.2      2018-10-16 [1] CRAN (R 3.5.0)                
#>  pkgload       1.0.2      2018-10-29 [1] CRAN (R 3.5.0)                
#>  prettyunits   1.0.2      2015-07-13 [1] CRAN (R 3.5.0)                
#>  processx      3.2.1      2018-12-05 [1] CRAN (R 3.5.1)                
#>  ps            1.3.0      2018-12-21 [1] CRAN (R 3.5.0)                
#>  purrr       * 0.3.0      2019-01-27 [1] CRAN (R 3.5.2)                
#>  R6            2.4.0      2019-02-14 [1] CRAN (R 3.5.2)                
#>  Rcpp          1.0.0.1    2019-01-07 [1] Github (RcppCore/Rcpp@0c9f683)
#>  remotes       2.0.2.9000 2019-01-29 [1] local                         
#>  rlang         0.3.1      2019-01-08 [1] CRAN (R 3.5.2)                
#>  rmarkdown     1.11       2018-12-08 [1] CRAN (R 3.5.0)                
#>  rprojroot     1.3-2      2018-01-03 [1] CRAN (R 3.5.0)                
#>  sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 3.5.1)                
#>  stringi       1.3.1      2019-02-13 [1] CRAN (R 3.5.2)                
#>  stringr       1.4.0      2019-02-10 [1] CRAN (R 3.5.2)                
#>  testthat      2.0.1      2018-10-13 [1] CRAN (R 3.5.0)                
#>  usethis       1.4.0      2018-08-14 [1] CRAN (R 3.5.0)                
#>  withr         2.1.2.9000 2018-10-25 [1] Github (r-lib/withr@be57595)  
#>  xfun          0.5        2019-02-20 [1] CRAN (R 3.5.2)                
#>  yaml          2.2.0      2018-07-25 [1] CRAN (R 3.5.0)                
#> 
#> [1] /Library/Frameworks/R.framework/Versions/3.5/Resources/library
@lionel-

This comment has been minimized.

Copy link
Member

commented Feb 25, 2019

Can you post your session infos please?

@ColinFay

This comment has been minimized.

Copy link
Contributor Author

commented Feb 25, 2019

library(purrr)
packageVersion("purrr")
#> [1] '0.3.0'
map(airquality, mean)
#> $Ozone
#> [1] NA
#> 
#> $Solar.R
#> [1] NA
#> 
#> $Wind
#> [1] 9.957516
#> 
#> $Temp
#> [1] 77.88235
#> 
#> $Month
#> [1] 6.993464
#> 
#> $Day
#> [1] 15.80392
p_mean <- partial(mean, na.rm = TRUE)
p_mean
#> <partialised>
#> function (...) 
#> mean(na.rm = TRUE, ...)
map(airquality, p_mean)
#> Error in UseMethod("mean"): no applicable method for 'mean' applied to an object of class "c('integer', 'numeric')"

Created on 2019-02-25 by the reprex package (v0.2.1)

Session info
devtools::session_info()
#> ─ Session info ──────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 3.4.4 (2018-03-15)
#>  os       macOS  10.14                
#>  system   x86_64, darwin15.6.0        
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  ctype    en_US.UTF-8                 
#>  tz       Europe/Paris                
#>  date     2019-02-25                  
#> 
#> ─ Packages ──────────────────────────────────────────────────────────────
#>  package     * version    date       lib source                          
#>  assertthat    0.2.0      2017-04-11 [1] CRAN (R 3.4.0)                  
#>  backports     1.1.3      2018-12-14 [1] CRAN (R 3.4.4)                  
#>  base64enc     0.1-3      2015-07-28 [1] CRAN (R 3.4.0)                  
#>  callr         3.0.0      2018-08-24 [1] CRAN (R 3.4.4)                  
#>  cli           1.0.1      2018-09-25 [1] CRAN (R 3.4.4)                  
#>  crayon        1.3.4      2017-09-16 [1] CRAN (R 3.4.1)                  
#>  debugme       1.1.0      2017-10-22 [1] CRAN (R 3.4.2)                  
#>  desc          1.2.0      2018-05-01 [1] CRAN (R 3.4.4)                  
#>  devtools      2.0.0.9000 2018-10-29 [1] Github (r-lib/devtools@4953bd6) 
#>  digest        0.6.18     2018-10-10 [1] CRAN (R 3.4.4)                  
#>  evaluate      0.12       2018-10-09 [1] CRAN (R 3.4.4)                  
#>  fs            1.2.6      2018-08-23 [1] CRAN (R 3.4.4)                  
#>  glue          1.3.0      2018-07-17 [1] RSPM (R 3.4.4)                  
#>  highr         0.7        2018-06-09 [1] CRAN (R 3.4.4)                  
#>  htmltools     0.3.6      2017-04-28 [1] CRAN (R 3.4.0)                  
#>  knitr         1.21       2018-12-10 [1] CRAN (R 3.4.4)                  
#>  magrittr      1.5        2014-11-22 [1] CRAN (R 3.4.0)                  
#>  memoise       1.1.0      2017-04-21 [1] CRAN (R 3.4.0)                  
#>  pkgbuild      1.0.2      2018-10-16 [1] CRAN (R 3.4.4)                  
#>  pkgload       1.0.1      2018-10-11 [1] CRAN (R 3.4.4)                  
#>  prettyunits   1.0.2      2015-07-13 [1] CRAN (R 3.4.0)                  
#>  processx      3.2.0      2018-08-16 [1] CRAN (R 3.4.4)                  
#>  ps            1.2.0      2018-10-16 [1] CRAN (R 3.4.4)                  
#>  purrr       * 0.3.0      2019-01-27 [1] CRAN (R 3.4.4)                  
#>  R6            2.3.0      2018-10-04 [1] CRAN (R 3.4.4)                  
#>  Rcpp          1.0.0      2018-11-07 [1] CRAN (R 3.4.4)                  
#>  remotes       2.0.2      2018-10-30 [1] CRAN (R 3.4.4)                  
#>  rlang         0.3.1.9000 2019-01-30 [1] Github (r-lib/rlang@7243c6d)    
#>  rmarkdown     1.10       2018-06-11 [1] CRAN (R 3.4.4)                  
#>  rprojroot     1.3-2      2018-01-03 [1] CRAN (R 3.4.3)                  
#>  sessioninfo   1.1.0      2018-09-25 [1] CRAN (R 3.4.4)                  
#>  stringi       1.2.4      2018-07-20 [1] CRAN (R 3.4.4)                  
#>  stringr       1.3.1      2018-05-10 [1] CRAN (R 3.4.4)                  
#>  testthat      2.0.0.9000 2018-07-20 [1] Github (r-lib/testthat@d43ed65) 
#>  usethis       1.4.0.9000 2019-02-06 [1] Github (r-lib/usethis@2e5f213)  
#>  withr         2.1.2.9000 2018-10-29 [1] Github (jimhester/withr@be57595)
#>  xfun          0.5        2019-02-20 [1] CRAN (R 3.4.4)                  
#>  yaml          2.2.0      2018-07-25 [1] CRAN (R 3.4.4)                  
#> 
#> [1] /Library/Frameworks/R.framework/Versions/3.4/Resources/library
@yutannihilation

This comment has been minimized.

Copy link
Member

commented Feb 25, 2019

I tried both the CRAN version and dev version of rlang, and both worked fine.

I guess the version of R matters on method dispatch.

@ColinFay

This comment has been minimized.

Copy link
Contributor Author

commented Feb 25, 2019

Just tried on a R 3.5.2 and it indeed works but fails with R 3.4.4
(with https://rstudio.cloud)

@elinw

This comment has been minimized.

Copy link

commented Feb 25, 2019

It could, but it has been working fine on both 3.4.x and 3.5.x up until now. By the way it is not just not finding the default, something like

p_mean <- partial(mean, na.rm = TRUE)
dat <- seq(as.Date("2011-07-01"), by=1, len=10)
p_mean(dat)

gets the same error. We got an email from CRAN about the breakage.

@lionel-

This comment has been minimized.

Copy link
Member

commented Feb 25, 2019

Sorry about that, I'll look into it this week.

@lionel- lionel- added the bug label Feb 25, 2019

@lionel- lionel- changed the title partial fails with S3 generics partial() fails with S3 generics on older R versions Feb 26, 2019

lionel- added a commit to lionel-/lowliner that referenced this issue Feb 26, 2019

@lionel- lionel- closed this in 542414c Feb 27, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.