在尝试使用tidyr::pivot_wider中的names_glue参数时,出现未使用的参数错误。这是帮助页面中的示例和我的错误:
library(tidyr)
us_rent_income %>%
pivot_wider(
names_from = variable,
names_glue = "{variable}_{.value}",
values_from = c(estimate, moe)
)
Error in pivot_wider(., names_from = variable, names_glue = "{variable}_{.value}", :
unused argument (names_glue = "{variable}_{.value}")
sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)
...
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] tidyr_1.0.2
loaded via a namespace (and not attached):
[1] tidyselect_1.0.0 compiler_3.6.1 magrittr_1.5 assertthat_0.2.1
[5] R6_2.4.1 pillar_1.4.3 glue_1.4.1 dplyr_0.8.5
[9] tibble_2.1.3 crayon_1.3.4 Rcpp_1.0.4 vctrs_0.2.4
[13] lifecycle_0.2.0 pkgconfig_2.0.3 rlang_0.4.5 purrr_0.3.3
我更新了tidyr
和glue
。
我应该注意,没有names_glue参数,效果很好:
us_rent_income %>%
pivot_wider(
names_from = variable,
names_sep = ".",
values_from = c(estimate, moe)
)
答案 0 :(得分:3)
根据更改日志,数据透视表(pivot_wider())似乎在1.1.0版中获得了names_glue参数。您显示的是1.0.2,对吧? Package ‘tidyr’ version 1.1.0-还要-Hadley's tidyr 1.1.0 blog announcement
这应该可以解决您的问题:
install.packages("tidyr")
library(tidyr)
us_rent_income %>%
pivot_wider(
names_from = variable,
names_glue = "{variable}_{.value}",
values_from = c(estimate, moe)
)
请注意,您可能还必须将vctrs软件包也更新到版本0.3.0。