1

From a clean restart in RStudio, I get an error when running tidyr::gather, and I can't see what I'm doing wrong.

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   

Can you help me find what the error message means? Google hasn't been my friend yet, and I don't recognize this as a known issue on the tidyr github site. My system claims to be up to date.

Thanks,

Bill

UPDATE: The suggestions sounded good, so I started a new session in a directory with no .RData file. Instead of using ESS or RStudio, I started a shell in Emacs and ran R --vanilla. It still fails:

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.

It works just fine on a Debian system.

Bill
  • 533
  • 1
  • 4
  • 16
  • 1
    I have found [this](https://stat.ethz.ch/pipermail/r-help/2008-June/163685.html), which suggests that this is maybe not a `tidyr` problem. The link suggests that the error message could be related to a corrupted .RData file. Try deleting .RData files in your default working directory (or the project directory, in case this happens with an RStudio project loaded). – Stibu Feb 01 '16 at 19:41
  • 1
    alternately try running R with the `--vanilla` flag set (sorry, not sure how to do this on Windows) to rule out weirdness with .RData files/.Rprofile/etc etc etc. – Ben Bolker Feb 01 '16 at 19:44

1 Answers1

0

I also had a problem on Windows x64 with tidyr::gather. My code had worked for ages, sat idle for a few months, then had never before seen errors. Tried removing .RData, like @Bill, to no avail. My error was different: "Error in loadNamespace(name) : there is no package called 'tidyselect'" despite tidyselect, by all appearances, being loaded, and persisting even after install.packages('tidyselect'). (Q: What does tidyselect have to do with anything?!?! A: It's on the backend of gather for tidyr 0.7.0+.) Perhaps our errors stemmed from the same underlying problem.

FWIW, for folks like me who come across this question while struggling with this issue, what finally did the trick for me was installing tidyselect from github: devtools::install_github('tidyverse/tidyselect'). Worked like a charm.