Skip to content

unnest chokes on syntactically invalid variable names #190

@lukeanker

Description

@lukeanker

unnest refuses to process data frames with syntactically invalid column names (e.g. containing spaces or beginning with numbers):

library(dplyr)
library(tidyr)
dat <- data.frame("foo bar" = I(list(1:2, 3)), check.names = F)
unnest(dat)
# Error in parse(text = x) : <text>:1:5: unexpected symbol
#1: foo bar
#         ^

unnest_(dat, names(dat))
# Error in parse(text = x) : <text>:1:5: unexpected symbol
#1: foo bar
#         ^

dat %>% rename(foobar=`foo bar`) %>% unnest
# Source: local data frame [3 x 1]
# 
#   foobar
#    (dbl)
#1      1
#2      2
#3      3

I don't know if it's a bug or if I'm using the function wrongly, but I think it worked in previous versions of tidyr. I'm packageVersion("tidyr") ‘0.4.1’ and packageVersion("dplyr") ‘0.4.3’

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions