Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Version 1.4.1.9000

* `melt.data.frame()` always drops the `dim` attribute on generated
value columns. (#77)

* `melt.data.frame()` throws when encountering objects of type `POSIXlt`,
and requests a conversion to the (much saner) `POSIXct` type.

Expand Down
8 changes: 6 additions & 2 deletions R/utils.r
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,18 @@ normalize_melt_arguments <- function(data, measure.ind, factorsAsStrings) {

## If we are going to be coercing any factors to strings, we don't want to
## copy the attributes
any.factors <- any( sapply( measure.ind, function(i) {
is.factor( data[[i]] )
any.factors <- any(sapply(measure.ind, function(i) {
is.factor(data[[i]])
}))

if (factorsAsStrings && any.factors) {
measure.attributes <- NULL
}

# Drop dimensions
if ("dim" %in% names(measure.attributes))
measure.attributes[["dim"]] <- NULL

list(
measure.attributes = measure.attributes,
factorsAsStrings = factorsAsStrings
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-melt.r
Original file line number Diff line number Diff line change
Expand Up @@ -226,3 +226,12 @@ test_that("melt.data.frame throws when encountering POSIXlt", {
expect_error(melt(df, measure.vars = c("x", "y")))

})

test_that("melt.data.frame drops dimensions on melted values", {

df <- data.frame(x = 1:5, y = letters[1:5], stringsAsFactors = FALSE)
attr(df$x, "dim") <- 5
melted <- melt(df, id = "y")
expect_true(is.null(attr(melted$value, "dim")))

})