Skip to content

expand / expand_ can't handle illegal column names #87

@markriseley

Description

@markriseley

Expand breaks when column names contain illegal characters eg spaces. This is in contrast to dplyr which handles them just fine. Example code below:

df <- data_frame(x = 1:2, y = 1:2)
expand(df, x, y)  # succeeds
expand_(df, c("x","y"))  # succeeds
df2 <- data_frame(`x 1` = 1:2, `y 1` = 1:2)
expand(df2,`x 1`,`y 1`) # Error in parse(text = x)...
expand_(df2, c("x 1","y 1")) # Error in parse(text = x)...
expand_(df2, sapply(names(df2),as.name))  # Error in parse(text = x)...
count_(df2, sapply(names(df2),as.name))  # dplyr 'count_' succeeds

I think the culprit might be in unique_vals() in expand.R

unique_vals <- function(data, dots) {
    df <- dplyr::distinct(dplyr::select_(data, .dots = dots))
    dplyr::arrange_(df, .dots = names(df))
}

I'm not that up on how lazyeval works but should 'names(df)' be 'dots' in the above?
Alternatively how about 'sapply(names(df),as.name)' ?

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