为什么尝试在tidyr::Pivot_Wide中使用NAMES_GLUE时出现错误? [英] Why do I get an error when trying to use names_glue in tidyr::pivot_wider?

查看:0
本文介绍了为什么尝试在tidyr::Pivot_Wide中使用NAMES_GLUE时出现错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在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
我更新了tidyrglue

我要注意的是,如果不使用NAMES_GLUE参数,则可以正常工作:

us_rent_income %>%
  pivot_wider(
    names_from = variable,
    names_sep = ".",
    values_from = c(estimate, moe)
  )

推荐答案

根据ChangeLog,似乎Pivot_Wide()在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。

这篇关于为什么尝试在tidyr::Pivot_Wide中使用NAMES_GLUE时出现错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆