【问题标题】:tidyr::gather example returns errortidyr::gather 示例返回错误
【发布时间】:2016-02-01 19:06:45
【问题描述】:

在 RStudio 中重新启动后,我在运行 tidyr::gather 时遇到错误,而且我看不到我做错了什么。

Restarting R session...
> library(tidyr)
> example(gather)
gather> library(dplyr)
Attaching package: ‘dplyr’
The following objects are masked from ‘package:stats’:
    filter, lag
The following objects are masked from ‘package:base’:
    intersect, setdiff, setequal, union
gather> # From http://stackoverflow.com/questions/1181060
gather> stocks <- data_frame(
gather+   time = as.Date('2009-01-01') + 0:9,
gather+   X = rnorm(10, 0, 1),
gather+   Y = rnorm(10, 0, 2),
gather+   Z = rnorm(10, 0, 4)
gather+ )

gather> gather(stocks, stock, price, -time)
Error in melt_dataframe(data, id_idx - 1L, gather_idx - 1L, as.character(key_col),  : 
  value of 'SET_ATTRIB' must be a pairlist or NULL, not a 'double'
> sessionInfo()
R version 3.2.3 (2015-12-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] dplyr_0.4.3 tidyr_0.4.0

loaded via a namespace (and not attached):
 [1] colorspace_1.2-6 scales_0.3.0     lazyeval_0.1.10  magrittr_1.5     R6_2.1.2         assertthat_0.1  
 [7] plyr_1.8.3       parallel_3.2.3   DBI_0.3.1        tools_3.2.3      gtable_0.1.2     Rcpp_0.12.3     
[13] ggplot2_2.0.0    grid_3.2.3       munsell_0.4.2   

您能帮我找出错误消息的含义吗? Google 还不是我的朋友,我不认为这是 tidyr github 网站上的一个已知问题。我的系统声称是最新的。

谢谢,

比尔

更新:这些建议听起来不错,所以我在没有 .RData 文件的目录中开始了一个新会话。我没有使用 ESS 或 RStudio,而是在 Emacs 中启动了一个 shell 并运行 R --vanilla。它仍然失败:

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

b:\Path\to\R> R --vanilla
  R --vanilla

R version 3.2.3 (2015-12-10) -- "Wooden Christmas-Tree"
Copyright (C) 2015 The R Foundation for Statistical Computing
Platform: x86_64-w64-mingw32/x64 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library('tidyr')
library('tidyr')

> example('gather')
example('gather')

gather> library(dplyr)

Attaching package: 'dplyr'

The following objects are masked from 'package:stats':

    filter, lag

The following objects are masked from 'package:base':

    intersect, setdiff, setequal, union


gather> # From http://stackoverflow.com/questions/1181060
gather> stocks <- data_frame(
gather+   time = as.Date('2009-01-01') + 0:9,
gather+   X = rnorm(10, 0, 1),
gather+   Y = rnorm(10, 0, 2),
gather+   Z = rnorm(10, 0, 4)
gather+ )

gather> gather(stocks, stock, price, -time)
Error in melt_dataframe(data, id_idx - 1L, gather_idx - 1L, as.character(key_col),  : 
  value of 'SET_ATTRIB' must be a pairlist or NULL, not a 'double'
Calls: example ... NextMethod -> gather_.data.frame -> melt_dataframe -> .Call
Execution halted

b:\Path\to\R> sessionInfo()
 sessionInfo()
'sessionInfo' is not recognized as an internal or external command,
operable program or batch file.

它在 Debian 系统上运行良好。

【问题讨论】:

  • 我找到了this,这表明这可能不是tidyr 的问题。该链接表明该错误消息可能与损坏的 .RData 文件有关。尝试删除默认工作目录(或项目目录,以防加载 RStudio 项目时发生这种情况)中的 .RData 文件。

标签: r tidyr


【解决方案1】:

我在使用tidyr::gather 的 Windows x64 上也遇到了问题。我的代码已经工作了很长时间,闲置了几个月,然后从未出现过错误。尝试删除 .RData,如 @Bill,但无济于事。我的错误是不同的:“Error in loadNamespace(name) : there is no package called 'tidyselect'”尽管 tidyselect,从所有外观来看,被加载,并且即使在install.packages('tidyselect') 之后仍然存在。 (问:tidyselect 和什么有什么关系?!?!答:It's on the backend of gather for tidyr 0.7.0+.)也许我们的错误源于同一个潜在问题。

FWIW,对于像我这样在解决这个问题时遇到这个问题的人来说,最终对我有用的是从 github 安装 tidyselect:devtools::install_github('tidyverse/tidyselect')。像魅力一样工作。

【讨论】:

    猜你喜欢
    • 2015-06-08
    • 2017-03-06
    • 1970-01-01
    • 2017-09-17
    • 1970-01-01
    • 2018-06-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多