Skip to content
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

dcast formula fails to resolve ... when column names have spaces #67

Open
saurfang opened this issue May 22, 2015 · 2 comments
Open

dcast formula fails to resolve ... when column names have spaces #67

saurfang opened this issue May 22, 2015 · 2 comments

Comments

@saurfang
Copy link

library(reshape2)
aqm <- melt(airquality, id=c("month", "day"), na.rm=TRUE)
colnames(aqm) <- c("my month" , "my day", "variable", "value")
dcast(aqm, ... ~ variable, value.var = "value")

Throws exception

Error in parse(text = x) : <text>:1:4: unexpected symbol
1: my month
       ^

This becomes a problem when I read data using readr which preserves the column names as-is (I like your not messing with my column names by the way). Now if I want to do any dcast using ... shorthand, it would fail. I can work around by constructing the formula manually/programmatically and quote the symbol properly.

@philpav
Copy link

philpav commented Mar 12, 2019

The problem is still present :(

@MHBailey
Copy link

MHBailey commented Mar 26, 2020

It's not pretty, but here is a work-around:

newdf <- dcast(aqm, aqm$'my month' + aqm$'my day' ~ variable, value.var = "value")
colnames(newdf)[1] <- "my month"
colnames(newdf)[2] <- "my day"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants