Skip to content

string coercion affects c() #37

@gergness

Description

@gergness

Was testing things out after reading Hadley's blog post, and found this edge case:

When using c(), we still get errors when combining string names and column numbers. Is it possible to work around this, as in :?

library(tidyselect)

vars_select(names(mtcars), c(starts_with("m"), "cyl"))
#> Error: Strings must match column names. Unknown columns: 1


vars_select(names(mtcars), starts_with("m") : "cyl")
#>   mpg   cyl 
#> "mpg" "cyl" 

If you can't fix it, the blog post is a little inconsistent about whether this will work. The paragraph after the code block implies it will work for c()

Luckily tidyselect 0.2.0 also introduces a few features that help writing safer code for data expressions. First, the support for strings and character vectors has been improved. All data expressions fully support strings. It is now valid to supply strings to - and ::
...
Note that this only applies to c(), - or : because it would not make sense to write seq("name", "mass")

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