I use melt.data.frame
from the reshape2
in a package. For reasons I cannot control, I've had users load my package (which imports reshape2
)...then load the reshape
package, causing future errors from my package (an official Warning...and incorrect output for my code).
I've seen this discussion: Reshape package masking preventing melt from naming columns
So I know I can use reshape2:::melt.data.frame
to prevent the conflict, but that generates a Note on check that I'd rather avoid. The gather
function in tidyr
doesn't solve it either. Here's a reproducible example:
library(reshape2)
df <- data.frame(x=rep("a",4),
y=c(1:3,NA),
key=c("g","g","c","d"),
stringsAsFactors = FALSE)
melt(df,id.vars = "key")
library(reshape)
melt(df,id.vars = "key")
reshape2::melt(df,id.vars = "key")
reshape2:::melt.data.frame(df,id.vars = "key") #No problem
reshape2::melt(df, measure.vars = c("x","y"),
variable.name = "variable",
value.name = "value", na.rm = FALSE)
library(tidyr)
gather(df, variable, value, -key)
gather_(df, "variable", "value", c("x","y"))