Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
spread() fails with empty data frame #269
library(tidyverse) df <- tibble(x = character(), y = numeric(), z = character()) spread(df, x, y) #> Error in enc2utf8(col_names(col_labels, sep = sep)): argumemt is not a character vector df2 <- df[c("x", "y")] spread(df2, x, y) #> Error: Duplicate identifiers for rows (1, 2)
I'm picking this one up - I'd like to clarify the outcomes that should occur for the above examples:
If a user calls spread on an empty data frame with a key/value pair of columns, which (of course by definition here) are empty then there are no matched key-value pairs and what I see happening is essentially those columns would be dropped because there are no keys to put as columns.
Following on that:
referenced this issue
Mar 15, 2017
I have run into this issue a number of times, and I'm wondering if it might be possible to throw an error if
Perhaps I'm being too egocentric, but I can't think of a time where I would want to
I'm pretty sure @cb4ds suggestion is the right approach. @markhwhiteii, I agree that it's probably not useful but in my experience it seems to work out easier in the long-run if operations on empty data frames do return values rather than throwing errors.
@cb4ds are you still interested in working on this? I'll be working on tidyr for the next few weeks and I'd be very happy to review a PR. (If I don't hear from you within a couple of days I'll assume you're not interested and I'll do it).