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

Melt Function Inconsistency with reshape2 Version #780

Closed
dardesta opened this issue Aug 21, 2014 · 3 comments
Closed

Melt Function Inconsistency with reshape2 Version #780

dardesta opened this issue Aug 21, 2014 · 3 comments
Assignees
Milestone

Comments

@dardesta
Copy link

I have a transpose function that imitates the arguments used in SAS.

transpose = function(input, by, var){
melt(input, id.vars = by, measure.vars=var)
}

Function Call

transpose(myData, by="Year")

This function works if myData is a data frame, but it returns an error if myData is a data table.

Error in melt.data.table(input, id.vars = by, measure.vars = var) :
argument "var" is missing, with no default

This will work if I default var to a NULL value, but then the data frame version will result in an error.

My question is: Is there a reason for the inconsistency? It would be nice to have melt.data.table suppor missing arguments so that there is not a need for the programmer to check the class of myData.

@arunsrinivasan
Copy link
Member

@dardesta, thanks for the report. But, could you please provide a minimal reproducible example - what's myData, var, by etc..? So that I can try to reproduce the issue. Thanks.

@dardesta
Copy link
Author

Sure. I'll use the data.table example.

library(reshape2)
library(data.table)

DF = data.frame(x=rep(c("a","b","c"),each=3), y=c(1,3,6), v=1:9)
DT = data.table(x=rep(c("a","b","c"),each=3), y=c(1,3,6), v=1:9)

transpose = function(input, by, var, id, varName="variable", valueName="value"){
    melt(input, id.vars = by, measure.vars=var)
}

#Data frame test
transpose(DF, by="x")
transpose(DF)

#Data table test
transpose(DT, by="x")
transpose(DT)

@arunsrinivasan
Copy link
Member

@dardesta, great example! Thanks. Was easy enough to fix now (although just to be consistent with melt.data.frame). Will commit soon.

@arunsrinivasan arunsrinivasan added this to the v1.9.4 milestone Sep 23, 2014
@arunsrinivasan arunsrinivasan self-assigned this Sep 23, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants