R 3.6 中 mutate_at() 的问题

Ble*_*ded 2 r dplyr

我一直在使用dplyr::mutate_at()没有任何问题。但是更新到 R 3.6 后,它给出了一个错误信息。例如,

library(dplyr)
salary <-
  structure(
    list(S = c(13876, 11608, 18701, 11283, 11767, 20872), X = c(1, 1, 1, 1, 1, 2), E = c(1, 3, 3, 2, 3, 2), M = c(1, 0, 1, 0, 0, 1)), 
    row.names = c(NA, -6L), class = c("tbl_df", "tbl", "data.frame")
  )
salary
#> # A tibble: 6 x 4
#>       S     X     E     M
#>   <dbl> <dbl> <dbl> <dbl>
#> 1 13876     1     1     1
#> 2 11608     1     3     0
#> 3 18701     1     3     1
#> 4 11283     1     2     0
#> 5 11767     1     3     0
#> 6 20872     2     2     1
Run Code Online (Sandbox Code Playgroud)

3.5.3

在这里,我尝试应用factor功能对每一个EM列使用dplyr::mutate_at()

salary %>% 
  mutate_at(.vars = vars("E", "M"), .funs = list(~factor))
#> # A tibble: 6 x 4
#>       S     X E     M    
#>   <dbl> <dbl> <fct> <fct>
#> 1 13876     1 1     1    
#> 2 11608     1 3     0    
#> 3 18701     1 3     1    
#> 4 11283     1 2     0    
#> 5 11767     1 3     0    
#> 6 20872     2 2     1
Run Code Online (Sandbox Code Playgroud)

我可以在3.5.3版本中得到这个输出。

sessionInfo()
#> R version 3.5.3 (2019-03-11)
#> Platform: x86_64-apple-darwin15.6.0 (64-bit)
#> Running under: macOS Mojave 10.14.5
#> 
#> Matrix products: default
#> BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib
#> 
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] dplyr_0.8.0.1
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.1       fansi_0.4.0      utf8_1.1.4       crayon_1.3.4    
#>  [5] digest_0.6.18    assertthat_0.2.1 R6_2.4.0         magrittr_1.5    
#>  [9] evaluate_0.13    pillar_1.3.1     cli_1.1.0        rlang_0.3.3     
#> [13] stringi_1.4.3    rmarkdown_1.12   tools_3.5.3      stringr_1.4.0   
#> [17] glue_1.3.1       purrr_0.3.2      xfun_0.5         yaml_2.2.0      
#> [21] compiler_3.5.3   pkgconfig_2.0.2  htmltools_0.3.6  tidyselect_0.2.5
#> [25] knitr_1.22       tibble_2.1.1
Run Code Online (Sandbox Code Playgroud)

3.6

但是,当我在另一个带有版本的笔记本中运行完全相同的代码R 3.6

sessionInfo()
#> R version 3.6.0 (2019-04-26)
#> Platform: x86_64-apple-darwin15.6.0 (64-bit)
#> Running under: macOS Mojave 10.14.5
#> 
#> Matrix products: default
#> BLAS:   /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
#> 
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#> [1] dplyr_0.8.1
#> 
#> loaded via a namespace (and not attached):
#>  [1] Rcpp_1.0.1       knitr_1.23       magrittr_1.5     tidyselect_0.2.5
#>  [5] R6_2.4.0         rlang_0.3.4      fansi_0.4.0      stringr_1.4.0   
#>  [9] tools_3.6.0      xfun_0.7         utf8_1.1.4       cli_1.1.0       
#> [13] htmltools_0.3.6  yaml_2.2.0       assertthat_0.2.1 digest_0.6.18   
#> [17] tibble_2.1.1     crayon_1.3.4     purrr_0.3.2      vctrs_0.1.0     
#> [21] zeallot_0.1.0    glue_1.3.1       evaluate_0.13    rmarkdown_1.12  
#> [25] stringi_1.4.3    compiler_3.6.0   pillar_1.4.0     backports_1.1.4 
#> [29] pkgconfig_2.0.2
Run Code Online (Sandbox Code Playgroud)

我收到以下错误消息。

salary %>% 
  mutate_at(.vars = vars("E", "M"), .funs = list(~factor))
#> Error: Column `E` is of unsupported type function
Run Code Online (Sandbox Code Playgroud)

R几天前升级后出现此错误。这真的是由于升级而发生的R吗?

还是另有原因?

Mar*_*nar 5

试试salary %>% mutate_at(.vars = vars("E", "M"), factor)。使用list()包装器(可能)没有必要(或正确)。