Skip to content

Conversation

@lionel-
Copy link

@lionel- lionel- commented Dec 10, 2015

Currently melt_dataframe() creates names attributes that aren't necessarily the same length as the output vector, which makes the print method crash.

# Can only create named column vectors with dplyr
df <- dplyr::data_frame(col1 = c(a = 1, b = 2), col2 = c(a = 10, b = 20))
df <- tidyr::gather(df, "col", "value")

str(df$value)
## [1] "numeric"
##  Named num [1:4] 1 2 10 20
##  - attr(*, "names")= chr [1:2] "a" "b"

print(df$value)
##  *** caught segfault ***
## address 0x400000ae, cause 'memory not mapped'
##
## Traceback:
##  1: print.default(df$value)
##  2: print(df$value)
##
## Possible actions:
## 1: abort (with core dump, if enabled)
## 2: normal R exit
## 3: exit R without saving workspace
## 4: exit R saving workspace
## Selection:

This fix concatenates the names of the melted vectors so that the output is appropriately named.

It also takes care of dim and dimnames because melt_dataframe() uses SET_ATTRIB wihch bypasses the sanity checks that are normally triggered when modifying those attributes from R, and thus also break various consistency assumptions. These attributes are now simply discarded.

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

Successfully merging this pull request may close these issues.

1 participant