-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rename() and error - attempt to use zero-length variable name #817
Comments
Can you please provide a reproducible example? |
Hi Dr. Wickham, Here is a sample of what I am working on. I've updated the code to be minimal as possible. library(XML)
library(httr)
library(stringr)
library(lubridate)
library(plyr)
library(dplyr)
fe.url <- "https://docs.google.com/spreadsheets/d/0Aul9Ys3cd80fdHNuRG5VeWpfbnU4eVdIWTU3Q0xwSEE/pubhtml"
raw.data <- content(GET(fe.url))
sheets <- readHTMLTable(raw.data, header = T, stringsAsFactors = F, trim = T)
head <- data.frame(sheets[[2]])
data <- data.frame(sheets[[3]])
head[34] <- NULL
names(data) <- head[1, ]
names(data) <- toupper(names(data))
names(data) <- str_replace_all(names(data), "[[:punct:]]", "")
names(data) <- str_replace_all(names(data)," ", "_")
data[1] <- NULL
data <- data[!sapply(data, function(x) all(x == ""))]
date <- data %>%
rename(DATE = DATE_OF_INJURY_RESULTING_IN_DEATH_MONTHDAYYEAR) %>%
mutate(DATE = as.Date(DATE, "%B %d, %Y"),
DATE = ymd(DATE),
MONTH = as.integer(month(DATE, label = F)),
DAY = as.integer(day(DATE)),
YEAR = as.integer(year(DATE))) Error in mutate_impl(.data, dots) : attempt to use zero-length variable name |
Please make a minimal example that just illustrates the bug |
Yep. I get that:
With a fresh install of Can you come up with some data without all the web scraping business. Also, was this with the development version. My guess is that this is related to #705, as:
|
I think I found the issue after creating toy examples in my attempt to replicate the error. Here are what I believe to be the problematic variables (last 3): When I used rename() on the date variables, it worked fine. The error shows up when trying to run mutate() on the data. I guess select() worked in this case because the problematic variables were removed prior to mutate(). So I guess there's a lot more running under the hood than a transformation on a single column? |
would you share this toy example of yours please ? |
Can you please read http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example and then create a issue? |
I got this same error in a very different context. It seems dplyr doesn't like variables with empty names. This seems reasonable. data = data_frame(a = 2, b = 3) |
I just ran into the same issue as @bramtayl, calling mutate on a data.frame with an empty-named variable. I negative-selected that variable and that allowed the mutate call to run. |
I think this issue is solved when using select(); however, it requires that I cbind() the mutated string data (date character string converted to numeric using as.Date() in this case). Can rename() function like select() so that I do not have to cbind() later?
The text was updated successfully, but these errors were encountered: