【发布时间】: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 文件。 -