-
Notifications
You must be signed in to change notification settings - Fork 129
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Referencing column with [[ ]] fails when column name is created from glue #778
Comments
An additional note, using |
Slightly more minimal reprex: library(tibble)
#> Warning: package 'tibble' was built under R version 3.6.2
df <- tibble(a = 1, b = 2)
df[[glue::glue("c")]]
#> NULL
df[[glue::glue("c")]] <- "bar"
#> Error: Can't assign to columns that don't exist.
#> x Column `c` doesn't exist. Created on 2020-06-05 by the reprex package (v0.3.0) |
This should be solved upstream, otherwise we'll end up replicating lots of vctrs logic here: library(vctrs)
vec_as_location(glue::glue("a"), 26, letters)
#> [1] 1
vec_as_location2(glue::glue("a"), 26, letters)
#> [1] 1
foo <- function(x) {
structure(x, class = "foo")
}
vec_as_location(foo("a"), 26, letters)
#> Error: Must subset elements with a valid subscript vector.
#> x Subscript has the wrong type `foo`.
#> ℹ It must be logical, numeric, or character.
vec_as_location2(foo("a"), 26, letters)
#> Error: Must extract element with a single valid subscript.
#> x Subscript has the wrong type `foo`.
#> ℹ It must be numeric or character. Created on 2020-07-05 by the reprex package (v0.3.0) |
On the other hand, we can use |
Now: library(tibble)
df <- tibble(a = 1, b = 2)
df[[glue::glue("c")]]
#> NULL
df[[glue::glue("c")]] <- "bar"
df
#> # A tibble: 1 x 3
#> a b c
#> <dbl> <dbl> <chr>
#> 1 1 2 bar Created on 2020-07-06 by the reprex package (v0.3.0) |
tibble 3.0.2 - `[[` works with classed indexes again, e.g. created with `glue::glue()` (#778). - `add_column()` works without warning for 0-column data frames (#786). - `tribble()` now better handles named inputs (#775) and objects of non-vtrs classes like `lubridate::Period` (#784) and `formattable::formattable` (#785). - Subsetting and subassignment are faster (#780, #790, #794). - `is.null()` is preferred over `is_null()` for speed. - Implement continuous benchmarking (#793). - `is_vector_s3()` is no longer reexported from pillar (#789).
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary. |
Newly upgraded to tibble 3.0.1 and referencing a column using
[[ ]]
no longer seems to work if the column name is created usingglue::glue
.Casting the return as a character seems to work ok.
The text was updated successfully, but these errors were encountered: