Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么在tidyr::pivot\u中尝试使用名称时出错?_R_Tidyr - Fatal编程技术网

为什么在tidyr::pivot\u中尝试使用名称时出错?

为什么在tidyr::pivot\u中尝试使用名称时出错?,r,tidyr,R,Tidyr,尝试在中使用names\u 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 = v

尝试在中使用names\u 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)
  )

根据变更日志,pivot_wider()似乎在1.1.0版中获得了names_glue参数。你正在播放1.0.2,对吗-此外—

这将解决您的问题:

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版。

谢谢。我的错误是使用
update.packages()
而不是安装最新版本。作为将来的参考,
install.packages(“tidyr”)
还安装最新版本的
vctrs