What I expected to work:
columnsOfInterest = c("Year", "ID1", starts_with("Tmin"))
bind_rows(read_csv("file1.csv", col_select = columnsOfInterest),
read_csv("file2.csv", col_select = columnsOfInterest))
What actually happened:
Error:
! `starts_with()` must be used within a *selecting* function.
ℹ See <https://tidyselect.r-lib.org/reference/faq-selection-context.html>.
Run `rlang::last_error()` to see where the error occurred.
> rlang::last_error()
<error/rlang_error>
Error:
! `starts_with()` must be used within a *selecting* function.
ℹ See <https://tidyselect.r-lib.org/reference/faq-selection-context.html>.
---
Backtrace:
1. tidyselect::starts_with("Tmin")
3. tidyselect::peek_vars(fn = "starts_with")
Run `rlang::last_trace()` to see the full context.
> rlang::last_trace()
<error/rlang_error>
Error:
! `starts_with()` must be used within a *selecting* function.
ℹ See <https://tidyselect.r-lib.org/reference/faq-selection-context.html>.
---
Backtrace:
▆
1. └─tidyselect::starts_with("Tmin")
2. ├─vars %||% peek_vars(fn = "starts_with")
3. └─tidyselect::peek_vars(fn = "starts_with")
4. └─rlang::abort(msg, call = NULL)
What the best workaround appears to be:
bind_rows(read_csv("file1.csv", col_select = c("Year", "ID1", starts_with("Tmin")),
read_csv("file2.csv", col_select = c("Year", "ID1", starts_with("Tmin")))
It seems strange to force users loading a bunch of similar .csv files to repeatedly indicate col_select rather than declaring it once. As with many such things it's not a big deal once you figure out what to do, though I did find the linked FAQ and other readr and dplyr documentation to have no relevant content.
It'd be nice to be able to write more proper code instead of relying on find/replace to maintain many hardcoded instances of the same thing. This is, as usual, a trivialized repex—the actual c() statement is considerably more complex—and I certainly wasn't expecting which line of code a c() was declared in would influence whether the declaration was valid.
I'm putting this issue in tidyselect since it seems like this might be worth a look from the context of dplyr::select() mini-language design it appears this is the repo which covers that. From the backtrace it seems peek_vars() might be prematurely positioned.
What I expected to work:
What actually happened:
What the best workaround appears to be:
It seems strange to force users loading a bunch of similar .csv files to repeatedly indicate
col_selectrather than declaring it once. As with many such things it's not a big deal once you figure out what to do, though I did find the linked FAQ and other readr and dplyr documentation to have no relevant content.It'd be nice to be able to write more proper code instead of relying on find/replace to maintain many hardcoded instances of the same thing. This is, as usual, a trivialized repex—the actual
c()statement is considerably more complex—and I certainly wasn't expecting which line of code ac()was declared in would influence whether the declaration was valid.I'm putting this issue in tidyselect since it seems like this might be worth a look from the context of dplyr::select() mini-language design it appears this is the repo which covers that. From the backtrace it seems
peek_vars()might be prematurely positioned.