tidyr :: gather示例返回错误

时间:2016-02-01 19:06:46

标签: r tidyr

从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系统上运行得很好。

1 个答案:

答案 0 :(得分:0)

在Windows x64上,tidyr::gather也有问题。我的代码已经使用了很长时间,闲置了几个月,然后再也从未见过错误。尝试删除@bill之类的 .RData 无济于事。我的错误是不同的:尽管进行了tidyselect,但从外观上看,“ Error in loadNamespace(name) : there is no package called 'tidyselect'”一直被加载,甚至在install.packages('tidyselect')之后仍然存在。 (问:tidyselect与什么有关系?!?!A:It's on the backend of gather for tidyr 0.7.0+.)也许我们的错误源于相同的潜在问题。

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