diff --git a/dev/news/index.html b/dev/news/index.html index c6c2988..8a0665d 100644 --- a/dev/news/index.html +++ b/dev/news/index.html @@ -50,8 +50,6 @@

eval_select() and eval_relocate() gain a new error_arg argument that can be specified to throw a better error message when allow_empty = FALSE or allow_rename = FALSE (@olivroy, #327).

  • vars_pull() now also warns when using .data (#335). Please use string-quotation programmatic usage, consistently with other tidyselect contexts.

  • num_range() now recycles its arguments using tidyverse rules (#355). In addition, it gains a cross argument that allows you to take the cartesian product of these arguments instead.

  • -
  • eval_select(allow_empty = FALSE) gains a new argument to yield a better error message in case of empty selection (@olivroy, #327)

  • -
  • eval_select() and eval_relocate() gain a new error_arg argument that can be specified to throw a better error message when allow_empty = FALSE.

  • eval_select() and eval_relocate() throw a classed error message when allow_empty = FALSE (@olivroy, #347).

  • diff --git a/dev/pkgdown.yml b/dev/pkgdown.yml index a580c8b..c025c47 100644 --- a/dev/pkgdown.yml +++ b/dev/pkgdown.yml @@ -4,7 +4,7 @@ pkgdown_sha: ~ articles: syntax: syntax.html tidyselect: tidyselect.html -last_built: 2024-10-28T14:32Z +last_built: 2024-10-28T15:54Z urls: reference: https://tidyselect.r-lib.org/reference article: https://tidyselect.r-lib.org/articles diff --git a/dev/search.json b/dev/search.json index 3a6bc11..a43773c 100644 --- a/dev/search.json +++ b/dev/search.json @@ -1 +1 @@ -[{"path":[]},{"path":"https://tidyselect.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"our-pledge","dir":"","previous_headings":"","what":"Our Pledge","title":"Contributor Covenant Code of Conduct","text":"members, contributors, leaders pledge make participation community harassment-free experience everyone, regardless age, body size, visible invisible disability, ethnicity, sex characteristics, gender identity expression, level experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, sexual identity orientation. pledge act interact ways contribute open, welcoming, diverse, inclusive, healthy community.","code":""},{"path":"https://tidyselect.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"our-standards","dir":"","previous_headings":"","what":"Our Standards","title":"Contributor Covenant Code of Conduct","text":"Examples behavior contributes positive environment community include: Demonstrating empathy kindness toward people respectful differing opinions, viewpoints, experiences Giving gracefully accepting constructive feedback Accepting responsibility apologizing affected mistakes, learning experience Focusing best just us individuals, overall community Examples unacceptable behavior include: use sexualized language imagery, sexual attention advances kind Trolling, insulting derogatory comments, personal political attacks Public private harassment Publishing others’ private information, physical email address, without explicit permission conduct reasonably considered inappropriate professional setting","code":""},{"path":"https://tidyselect.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"enforcement-responsibilities","dir":"","previous_headings":"","what":"Enforcement Responsibilities","title":"Contributor Covenant Code of Conduct","text":"Community leaders responsible clarifying enforcing standards acceptable behavior take appropriate fair corrective action response behavior deem inappropriate, threatening, offensive, harmful. Community leaders right responsibility remove, edit, reject comments, commits, code, wiki edits, issues, contributions aligned Code Conduct, communicate reasons moderation decisions appropriate.","code":""},{"path":"https://tidyselect.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"scope","dir":"","previous_headings":"","what":"Scope","title":"Contributor Covenant Code of Conduct","text":"Code Conduct applies within community spaces, also applies individual officially representing community public spaces. Examples representing community include using official e-mail address, posting via official social media account, acting appointed representative online offline event.","code":""},{"path":"https://tidyselect.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"enforcement","dir":"","previous_headings":"","what":"Enforcement","title":"Contributor Covenant Code of Conduct","text":"Instances abusive, harassing, otherwise unacceptable behavior may reported community leaders responsible enforcement codeofconduct@posit.co. complaints reviewed investigated promptly fairly. community leaders obligated respect privacy security reporter incident.","code":""},{"path":"https://tidyselect.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"enforcement-guidelines","dir":"","previous_headings":"","what":"Enforcement Guidelines","title":"Contributor Covenant Code of Conduct","text":"Community leaders follow Community Impact Guidelines determining consequences action deem violation Code Conduct:","code":""},{"path":"https://tidyselect.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_1-correction","dir":"","previous_headings":"Enforcement Guidelines","what":"1. Correction","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Use inappropriate language behavior deemed unprofessional unwelcome community. Consequence: private, written warning community leaders, providing clarity around nature violation explanation behavior inappropriate. public apology may requested.","code":""},{"path":"https://tidyselect.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_2-warning","dir":"","previous_headings":"Enforcement Guidelines","what":"2. Warning","title":"Contributor Covenant Code of Conduct","text":"Community Impact: violation single incident series actions. Consequence: warning consequences continued behavior. interaction people involved, including unsolicited interaction enforcing Code Conduct, specified period time. includes avoiding interactions community spaces well external channels like social media. Violating terms may lead temporary permanent ban.","code":""},{"path":"https://tidyselect.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_3-temporary-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"3. Temporary Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: serious violation community standards, including sustained inappropriate behavior. Consequence: temporary ban sort interaction public communication community specified period time. public private interaction people involved, including unsolicited interaction enforcing Code Conduct, allowed period. Violating terms may lead permanent ban.","code":""},{"path":"https://tidyselect.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_4-permanent-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"4. Permanent Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Demonstrating pattern violation community standards, including sustained inappropriate behavior, harassment individual, aggression toward disparagement classes individuals. Consequence: permanent ban sort public interaction within community.","code":""},{"path":"https://tidyselect.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"attribution","dir":"","previous_headings":"","what":"Attribution","title":"Contributor Covenant Code of Conduct","text":"Code Conduct adapted Contributor Covenant, version 2.1, available https://www.contributor-covenant.org/version/2/1/code_of_conduct.html. Community Impact Guidelines inspired [Mozilla’s code conduct enforcement ladder][https://github.com/mozilla/inclusion]. answers common questions code conduct, see FAQ https://www.contributor-covenant.org/faq. Translations available https://www.contributor-covenant.org/translations.","code":""},{"path":"https://tidyselect.r-lib.org/dev/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"MIT License","title":"MIT License","text":"Copyright (c) 2024 tidyselect authors Permission hereby granted, free charge, person obtaining copy software associated documentation files (“Software”), deal Software without restriction, including without limitation rights use, copy, modify, merge, publish, distribute, sublicense, /sell copies Software, permit persons Software furnished , subject following conditions: copyright notice permission notice shall included copies substantial portions Software. SOFTWARE PROVIDED “”, WITHOUT WARRANTY KIND, EXPRESS IMPLIED, INCLUDING LIMITED WARRANTIES MERCHANTABILITY, FITNESS PARTICULAR PURPOSE NONINFRINGEMENT. EVENT SHALL AUTHORS COPYRIGHT HOLDERS LIABLE CLAIM, DAMAGES LIABILITY, WHETHER ACTION CONTRACT, TORT OTHERWISE, ARISING , CONNECTION SOFTWARE USE DEALINGS SOFTWARE.","code":""},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"sets-of-variables","dir":"Articles","previous_headings":"","what":"Sets of variables","title":"Technical description of tidyselect","text":"tidyselect syntax sets variables, internally represented integer vectors locations. example, c(1L, 2L) represents set first second variables, c(1L, 2L, 1L). vector locations contains duplicates, normally treated element, since represent sets. exception occurs named elements whose names differ. names don’t match, treated different elements order allow renaming variable multiple names (see section Renaming variables). Today, syntax tidyselect generally designed around Boolean algebra, .e. recommend writing starts_with(\"\") & !ends_with(\"z\"). Earlier versions tidyselect flavour set operations, ’d write starts_with(\"\") - ends_with(\"b\"). set operations still supported, tidyselect represents variables internally, longer recommend Boolean algebra easy people understand.","code":""},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"bare-names","dir":"Articles","previous_headings":"Sets of variables","what":"Bare names","title":"Technical description of tidyselect","text":"Within data-expressions (see Evaluation section), bare names represent locations, .e. set size 1. following expressions equivalent:","code":"mtcars %>% select_loc(mpg:hp, !cyl, vs) #> mpg cyl disp hp drat wt qsec vs am gear carb #> 1 2 3 4 5 6 7 8 9 10 11 mtcars %>% select_loc(1:4, !2, 8) #> mpg cyl disp hp drat wt qsec vs am gear carb #> 1 2 3 4 5 6 7 8 9 10 11"},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"the-operator","dir":"Articles","previous_headings":"Sets of variables","what":"The : operator","title":"Technical description of tidyselect","text":": can used select consecutive variables two locations. returns corresponding sequence locations. bare names represent locations, easy select range variables:","code":"mtcars %>% select_loc(2:4) #> cyl disp hp #> 2 3 4 mtcars %>% select_loc(cyl:hp) #> cyl disp hp #> 2 3 4"},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"boolean-operators","dir":"Articles","previous_headings":"Sets of variables","what":"Boolean operators","title":"Technical description of tidyselect","text":"| operator takes union two sets: & operator takes intersection two sets: ! operator takes complement set: Taking intersection complement produces set difference:","code":"iris %>% select_loc(starts_with(\"Sepal\") | ends_with(\"Width\")) #> Sepal.Length Sepal.Width Petal.Width #> 1 2 4 iris %>% select_loc(starts_with(\"Sepal\") & ends_with(\"Width\")) #> Sepal.Width #> 2 iris %>% select_loc(!ends_with(\"Width\")) #> Sepal.Length Petal.Length Species #> 1 3 5 iris %>% select_loc(starts_with(\"Sepal\") & !ends_with(\"Width\")) #> Sepal.Length #> 1"},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"dots-and-c","dir":"Articles","previous_headings":"Sets of variables","what":"Dots and c()","title":"Technical description of tidyselect","text":"tidyselect functions can take dots, like dplyr::select(), named argument, like tidyr::pivot_longer(). latter case, dots syntax accessible via c(). fact ... syntax implemented c(...) thus completely equivalent. c(x, y, z) equivalent x | y | z:","code":"mtcars %>% select_loc(mpg, disp:hp) #> mpg disp hp #> 1 3 4 mtcars %>% select_loc(c(mpg, disp:hp)) #> mpg disp hp #> 1 3 4 iris %>% select_loc(starts_with(\"Sepal\"), ends_with(\"Width\"), Species) #> Sepal.Length Sepal.Width Petal.Width Species #> 1 2 4 5 iris %>% select_loc(starts_with(\"Sepal\") | ends_with(\"Width\") | Species) #> Sepal.Length Sepal.Width Petal.Width Species #> 1 2 4 5"},{"path":[]},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"name-combination-and-propagation","dir":"Articles","previous_headings":"Sets of variables > Renaming variables","what":"Name combination and propagation","title":"Technical description of tidyselect","text":"named inputs provided ... c(), selection renamed. inputs already named, outer inner names combined ... separator: Otherwise outer names propagated selected elements according following rules: data frames, numeric suffix appended columns must uniquely named. normal vectors, name simply assigned selected inputs. Combination propagation can composed using nested c():","code":"mtcars %>% select_loc(foo = c(bar = mpg, baz = cyl)) #> foo...bar foo...baz #> 1 2 mtcars %>% select_loc(foo = c(mpg, cyl)) #> foo1 foo2 #> 1 2 as.list(mtcars) %>% select_loc(foo = c(mpg, cyl)) #> foo foo #> 1 2 mtcars %>% select_loc(foo = c(bar = c(mpg, cyl))) #> foo...bar1 foo...bar2 #> 1 2"},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"set-combination-with-named-variables","dir":"Articles","previous_headings":"Sets of variables > Renaming variables","what":"Set combination with named variables","title":"Technical description of tidyselect","text":"Named elements special rules determine identities set. Unnamed elements match names: | c(foo = ) equivalent c(foo = ). & c(foo = ) equivalent c(foo = ). Named elements different names distinct: c(foo = ) & c(bar = ) equivalent c(). c(foo = ) | c(bar = ) equivalent c(foo = , bar = ). unnamed elements match named ones, possible select multiple elements rename one :","code":"iris %>% select_loc(!Species, foo = Sepal.Width) #> Sepal.Length foo Petal.Length Petal.Width #> 1 2 3 4"},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"predicate-functions","dir":"Articles","previous_headings":"Sets of variables","what":"Predicate functions","title":"Technical description of tidyselect","text":"Predicate function objects can supplied input env-expression, typically selection helper (). applied elements data, return TRUE FALSE indicate inclusion. Predicates env-expressions effectively expanded set variables represent:","code":"iris %>% select_loc(where(is.numeric)) #> Sepal.Length Sepal.Width Petal.Length Petal.Width #> 1 2 3 4 iris %>% select_loc(where(is.factor)) #> Species #> 5 iris %>% select_loc(where(is.numeric) | where(is.factor)) #> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> 1 2 3 4 5 iris %>% select_loc(where(is.numeric) & where(is.factor)) #> named integer(0)"},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"selection-helpers","dir":"Articles","previous_headings":"","what":"Selection helpers","title":"Technical description of tidyselect","text":"call selection helpers function inspects currently active variables peek_vars() returns selection. peek_vars() returns character vector names. returned selection can output conforming types described Data types section. Examples selection helpers all_of(), contains(), last_col(). selection helpers evaluated env-expressions (see Evaluation section).","code":""},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"supported-data-types","dir":"Articles","previous_headings":"","what":"Supported data types","title":"Technical description of tidyselect","text":"following data types can returned selection helpers forced via !! force() (latter works tidyselect treated env-expression, see Evaluation section): Vectors locations: Vectors names. matched transformed locations. Predicate functions. applied elements determine inclusion.","code":"iris %>% select_loc(force(c(1, 3))) #> Sepal.Length Petal.Length #> 1 3 iris %>% select_loc(force(c(\"Sepal.Length\", \"Petal.Length\"))) #> Sepal.Length Petal.Length #> 1 3 iris %>% select_loc(force(is.numeric)) #> Sepal.Length Sepal.Width Petal.Length Petal.Width #> 1 2 3 4"},{"path":[]},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"data-expressions-and-env-expressions","dir":"Articles","previous_headings":"Evaluation","what":"Data-expressions and env-expressions","title":"Technical description of tidyselect","text":"tidyselect typical tidy evaluation UI. main difference data masking. typical tidy eval function, expressions evaluated data-vars first scope, followed env-vars: possible bypass data frame variables forcing symbols looked environment !! .env: tidyselect, hierarchical data masking. Instead, expressions evaluated either context data frame user environment, without overlap. scope lookup depends kind expression: data-expressions evaluated data frame . includes bare symbols, boolean operators, -, :, c(). can’t refer environment-variables data-expression: env-expressions evaluated environment. includes calls mentioned , well symbols part calls. can’t refer data-variables data-expression: scoping unambiguous, can safely refer env-vars env-expression, without worry potential naming clashes data-vars: variable names character vector, safe refer env-var containing names all_of() env-expression: Note currently, env-vars still allowed data-expressions, compatibility. However process deprecated see note recommending use all_of() instead. note become deprecation warning future, error.","code":"mask <- function(data, expr) { rlang::eval_tidy(rlang::enquo(expr), data) } foo <- 10 cyl <- 200 # `cyl` represents the data frame column here: mtcars %>% mask(cyl * foo) #> [1] 60 60 40 60 80 60 80 40 40 60 60 80 80 80 80 80 80 40 40 40 40 80 80 #> [24] 80 80 40 40 40 80 60 80 40 mtcars %>% mask(!!cyl * foo) #> [1] 2000 mtcars %>% mask(.env$cyl * foo) #> [1] 2000 cyl_pos <- 2 mtcars %>% select_loc(mpg | cyl_pos) #> Error in `select_loc()`: #> ! Can't select columns that don't exist. #> ✖ Column `cyl_pos` doesn't exist. mtcars %>% select_loc(all_of(mpg)) #> Error in `select_loc()`: #> ℹ In argument: `all_of(mpg)`. #> Caused by error: #> ! object 'mpg' not found x <- data.frame(x = 1:3, y = 4:6, z = 7:9) # `ncol(x)` is an env-expression, so `x` represents the data frame in # the environment rather than the column in the data frame x %>% select_loc(2:ncol(x)) #> y z #> 2 3 y <- c(\"y\", \"z\") x %>% select_loc(all_of(y)) #> y z #> 2 3 mtcars %>% select_loc(cyl_pos) #> Warning: Using an external vector in selections was deprecated in tidyselect #> 1.1.0. #> ℹ Please use `all_of()` or `any_of()` instead. #> ℹ See . #> This warning is displayed once every 8 hours. #> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was #> generated. #> cyl #> 2"},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"arithmetic-operators","dir":"Articles","previous_headings":"Evaluation","what":"Arithmetic operators","title":"Technical description of tidyselect","text":"Within data-expressions (see Evaluation section), +, * / overridden cause error. prevent confusion stemming normal data masking usage variables can transformed fly:","code":"mtcars %>% select_loc(cyl^2) #> Error in `select_loc()`: #> ! Can't use arithmetic operator `^` in selection context. mtcars %>% select_loc(mpg * wt) #> Error in `select_loc()`: #> ! Can't use arithmetic operator `*` in selection context."},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"selecting-versus-renaming","dir":"Articles","previous_headings":"","what":"Selecting versus renaming","title":"Technical description of tidyselect","text":"select rename variants take types inputs type return value. important differences.","code":""},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"all-renaming-inputs-must-be-named","dir":"Articles","previous_headings":"Selecting versus renaming","what":"All renaming inputs must be named","title":"Technical description of tidyselect","text":"Unlike eval_select() can select without renaming, eval_rename() expects fully named selection. one several names missing, error thrown.","code":"mtcars %>% select_loc(mpg) #> mpg #> 1 mtcars %>% rename_loc(mpg) #> Error in `rename_loc()`: #> ! All renaming inputs must be named."},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"renaming-to-an-existing-variable-name","dir":"Articles","previous_headings":"Selecting versus renaming","what":"Renaming to an existing variable name","title":"Technical description of tidyselect","text":"input data data frame, tidyselect generally throws error duplicate column names selected, order respect invariant unique column names. selection can rename variable existing name latter part selection: possible renaming. However, name conflict can solved renaming existing variable another name:","code":"# Lists can have duplicates as.list(mtcars) %>% select_loc(foo = mpg, foo = cyl) #> foo foo #> 1 2 # Data frames cannot mtcars %>% select_loc(foo = mpg, foo = cyl) #> Error in `select_loc()`: #> ! Names must be unique. #> ✖ These names are duplicated: #> * \"foo\" at locations 1 and 2. mtcars %>% select_loc(cyl, cyl = mpg) #> Error in `select_loc()`: #> ! Names must be unique. #> ✖ These names are duplicated: #> * \"cyl\" at locations 1 and 2. mtcars %>% select_loc(disp, cyl = mpg) #> disp cyl #> 3 1 mtcars %>% rename_loc(cyl, cyl = mpg) #> Error in `rename_loc()`: #> ! All renaming inputs must be named. mtcars %>% rename_loc(disp, cyl = mpg) #> Error in `rename_loc()`: #> ! All renaming inputs must be named. mtcars %>% select_loc(foo = cyl, cyl = mpg) #> foo cyl #> 2 1 mtcars %>% rename_loc(foo = cyl, cyl = mpg) #> foo cyl #> 2 1"},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"duplicate-columns-in-data-frames","dir":"Articles","previous_headings":"","what":"Duplicate columns in data frames","title":"Technical description of tidyselect","text":"Normally data frame shouldn’t duplicate names. However, real world messy duplicates happen wild. tidyselect tries permissive can duplicates users can restore unique names select() rename(). First let’s create data frame duplicate names: duplicates part selection, simply ignored: duplicates selected, error: duplicate names can repaired renaming chosen locations:","code":"dups <- vctrs::new_data_frame(list(x = 1, y = 2, x = 3)) dups %>% select_loc(y) #> y #> 2 dups %>% select_loc(x) #> Error in `select_loc()`: #> ! Names must be unique. #> ✖ These names are duplicated: #> * \"x\" at locations 1 and 2. dups %>% select_loc(x, foo = 3) #> x foo #> 1 3 dups %>% rename_loc(foo = 3) #> foo #> 3"},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"acknowledgements","dir":"Articles","previous_headings":"","what":"Acknowledgements","title":"Technical description of tidyselect","text":"tidyselect syntax inspired base::subset() function written Peter Dalgaard. select parameter subset.data.frame() evaluated data mask column names bound locations data frame. allows : create sequences variable locations. locations can combined c(). selection interface set tone development tidyselect syntax.","code":"mtcars %>% subset(select = c(cyl, hp:wt)) #> # A tibble: 32 × 4 #> cyl hp drat wt #> #> 1 6 110 3.9 2.62 #> 2 6 110 3.9 2.88 #> 3 4 93 3.85 2.32 #> 4 6 110 3.08 3.22 #> # ℹ 28 more rows"},{"path":[]},{"path":"https://tidyselect.r-lib.org/dev/articles/tidyselect.html","id":"selections-as-dots-or-as-named-arguments","dir":"Articles","previous_headings":"Before we start","what":"Selections as dots or as named arguments","title":"Implementing tidyselect interfaces","text":"two major ways designing function takes selections. Passing dots dplyr::select(). Interpolating named arguments tidyr::pivot_longer(). case, multiple inputs can provided inside c() using boolean operators: general recommendation take dots main purpose function create new data structure based selection. selection accessory main purpose function, take named argument. doubt, recommend using named arguments easier change named argument dots way around. advice , see Making data ... section tidyverse design book.","code":"mtcars %>% dplyr::select(mpg, cyl) mtcars %>% pivot_longer(c(mpg, cyl)) mtcars %>% pivot_longer(mpg | cyl)"},{"path":"https://tidyselect.r-lib.org/dev/articles/tidyselect.html","id":"do-you-need-tidyselect","dir":"Articles","previous_headings":"Before we start","what":"Do you need tidyselect?","title":"Implementing tidyselect interfaces","text":"tools described vignette rather low level. Depending use case, may easier wrap dplyr::select(). ’ll get data frame containing columns selected user, can handle various ways. following examples illustrate write function takes selection data returns corresponding data frame capitalised names: main advantage lower level tidyselect tools offer bit information flexibility. Instead returning selected data, return locations selected elements inside input data. don’t need selected locations can afford dependency, may consider wrapping dplyr instead.","code":"# Passing dots toupper_dots <- function(data, ...) { sel <- dplyr::select(data, ...) rlang::set_names(sel, toupper) } # Interpolating a named argument with {{ }} toupper_arg <- function(data, arg) { sel <- dplyr::select(data, {{ arg }}) rlang::set_names(sel, toupper) } mtcars %>% toupper_dots(mpg:disp, vs) #> # A tibble: 32 x 4 #> MPG CYL DISP VS #> #> 1 21 6 160 0 #> 2 21 6 160 0 #> 3 22.8 4 108 1 #> 4 21.4 6 258 1 #> # … with 28 more rows mtcars %>% toupper_arg(c(mpg:disp, vs)) #> # A tibble: 32 x 4 #> MPG CYL DISP VS #> #> 1 21 6 160 0 #> 2 21 6 160 0 #> 3 22.8 4 108 1 #> 4 21.4 6 258 1 #> # … with 28 more rows"},{"path":"https://tidyselect.r-lib.org/dev/articles/tidyselect.html","id":"the-selection-evaluators","dir":"Articles","previous_headings":"","what":"The selection evaluators","title":"Implementing tidyselect interfaces","text":"tidyselect implemented non-standard evaluation (NSE). unique feature R language refers ability functions defuse (.e. delay execution) arguments, resume evaluation later on1. Crucially, evaluation can resumed different context according different rules, often domain-specific languages created R.","code":""},{"path":"https://tidyselect.r-lib.org/dev/articles/tidyselect.html","id":"defusing-and-resuming-evaluation-of-r-code","dir":"Articles","previous_headings":"The selection evaluators","what":"Defusing and resuming evaluation of R code","title":"Implementing tidyselect interfaces","text":"function argument defused, R halts evaluation code returns defused expression instead. expression contains code describes compute intended value. Defuse R code expr(): Defuse user’s R code enquo(): resume evaluation defused R code, use eval_tidy(): can resume evaluation data context passing data frame data argument: Resuming evaluation data context known data masking. data-vars inside data frame combined env-vars environment, making possible users refer data variables:","code":"own <- rlang::expr(1 + 2) own #> 1 + 2 fn <- function(arg) { expr <- rlang::enquo(arg) expr } user <- fn(1 + 2) user #> #> expr: ^1 + 2 #> env: global rlang::eval_tidy(own) #> [1] 3 rlang::eval_tidy(user) #> [1] 3 with_data <- function(data, x) { expr <- rlang::enquo(x) rlang::eval_tidy(expr, data = data) } NULL %>% with_data(mean(cyl) * 10) #> Error: object 'cyl' not found mtcars %>% with_data(mean(cyl) * 10) #> [1] 61.875"},{"path":"https://tidyselect.r-lib.org/dev/articles/tidyselect.html","id":"resuming-defused-r-code-with-tidyselect-rules","dir":"Articles","previous_headings":"The selection evaluators","what":"Resuming defused R code with tidyselect rules","title":"Implementing tidyselect interfaces","text":"Taking tidyselect selections functions follows principles. First defuse expression, resume evaluation. Instead eval_tidy(), need special interpreters eval_select() eval_rename(). Like eval_tidy(), take defused expression data. return vector locations selected elements: user renamed selected elements, names vector locations reflect new names. eval_select() likely variant ’ll need implement tidyselect functions.","code":"eval_select(rlang::expr(mpg), mtcars) #> mpg #> 1 eval_select(rlang::expr(c(mpg:disp, vs)), mtcars) #> mpg cyl disp vs #> 1 2 3 8 eval_select(rlang::expr(c(foo = mpg, bar = disp)), mtcars) #> foo bar #> 1 3 eval_rename(rlang::expr(c(foo = mpg, bar = disp)), mtcars) #> foo bar #> 1 3"},{"path":"https://tidyselect.r-lib.org/dev/articles/tidyselect.html","id":"simple-selections-with-dots","dir":"Articles","previous_headings":"The selection evaluators > Resuming defused R code with tidyselect rules","what":"Simple selections with dots","title":"Implementing tidyselect interfaces","text":"selecting function takes dots: Pass dots c() inside defused expression. Resume evaluation defused c() expression eval_select(). Use vector locations returned eval_select() subset rename input data. reimplement dplyr::select() 3 lines representing steps :","code":"select <- function(.data, ...) { expr <- rlang::expr(c(...)) pos <- eval_select(expr, data = .data) rlang::set_names(.data[pos], names(pos)) } mtcars %>% select(mpg, cyl) #> # A tibble: 32 × 2 #> mpg cyl #> #> 1 21 6 #> 2 21 6 #> 3 22.8 4 #> 4 21.4 6 #> # ℹ 28 more rows"},{"path":"https://tidyselect.r-lib.org/dev/articles/tidyselect.html","id":"simple-selections-with-named-arguments","dir":"Articles","previous_headings":"The selection evaluators > Resuming defused R code with tidyselect rules","what":"Simple selections with named arguments","title":"Implementing tidyselect interfaces","text":"selecting function takes named arguments, defusing step bit different. need use enquo() defuse function argument .","code":"select <- function(.data, cols) { expr <- rlang::enquo(cols) pos <- eval_select(expr, data = .data) rlang::set_names(.data[pos], names(pos)) } mtcars %>% select(c(mpg, cyl)) #> # A tibble: 32 × 2 #> mpg cyl #> #> 1 21 6 #> 2 21 6 #> 3 22.8 4 #> 4 21.4 6 #> # ℹ 28 more rows"},{"path":"https://tidyselect.r-lib.org/dev/articles/tidyselect.html","id":"renaming-selections","dir":"Articles","previous_headings":"The selection evaluators > Resuming defused R code with tidyselect rules","what":"Renaming selections","title":"Implementing tidyselect interfaces","text":"eval_rename() variant rarely needed mentioned completeness. First note eval_select() eval_rename() allow renaming variables: eval_rename() similar eval_select() constraints meant renaming variables place. particular throws error selected inputs unnamed. practice, eval_rename() accepts c() expression expr argument, inputs inside outermost c() must named: constraint, doesn’t make much sense take named argument, time ’ll want pass dots defused c() expression. way user can easily pass names selections: example use vector locations returned eval_rename(), implement dplyr::rename():","code":"eval_select(rlang::expr(c(foo = mpg)), mtcars) #> foo #> 1 eval_rename(rlang::expr(c(foo = mpg)), mtcars) #> foo #> 1 eval_rename(rlang::expr(mpg), mtcars) #> Error: #> ! All renaming inputs must be named. eval_rename(rlang::expr(c(mpg)), mtcars) #> Error: #> ! All renaming inputs must be named. eval_rename(rlang::expr(c(foo = mpg)), mtcars) #> foo #> 1 wrapper <- function(data, ...) { eval_rename(rlang::expr(c(...)), data) } mtcars %>% wrapper(foo = mpg, bar = hp:wt) #> foo bar1 bar2 bar3 #> 1 4 5 6 rename <- function(.data, ...) { pos <- eval_rename(rlang::expr(c(...)), .data) names(.data)[pos] <- names(pos) .data } mtcars %>% rename(foo = mpg, bar = hp:wt) #> # A tibble: 32 × 11 #> foo cyl disp bar1 bar2 bar3 qsec vs am gear carb #> #> 1 21 6 160 110 3.9 2.62 16.5 0 1 4 4 #> 2 21 6 160 110 3.9 2.88 17.0 0 1 4 4 #> 3 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1 #> 4 21.4 6 258 110 3.08 3.22 19.4 1 0 3 1 #> # ℹ 28 more rows"},{"path":"https://tidyselect.r-lib.org/dev/articles/tidyselect.html","id":"creating-selection-helpers","dir":"Articles","previous_headings":"","what":"Creating selection helpers","title":"Implementing tidyselect interfaces","text":"Tools like starts_with() contains() called selection helpers. tools inspect variable names currently available selection peek_vars(). variable names registered automatically eval_select() duration evaluation: properties temporarily available calling function like peek_vars() called descriptors. Descriptors useful easy compose. instance, user combine starts_with() ends_with() without worry passing variables environment can found: create new selection helper: Inspect variables peek_vars(). convention done argument user can override. Return one supported data types: vector names locations (latter recommended, see section handling duplicate variables), predicate function. fn argument makes error message informative helper used wrong context: variables inspected default argument, easy override. mostly useful unit tests:","code":"x <- rlang::expr(print(peek_vars())) invisible(eval_select(x, data = mtcars)) #> [1] \"mpg\" \"cyl\" \"disp\" \"hp\" \"drat\" \"wt\" \"qsec\" \"vs\" \"am\" \"gear\" #> [11] \"carb\" my_selector <- function(prefix, suffix) { intersect( starts_with(prefix), ends_with(suffix) ) } iris %>% select(my_selector(\"Sepal\", \"Length\")) #> # A tibble: 150 × 1 #> Sepal.Length #> #> 1 5.1 #> 2 4.9 #> 3 4.7 #> 4 4.6 #> # ℹ 146 more rows if_width <- function(n, vars = peek_vars(fn = \"if_width\")) { vars[nchar(vars) == n] } mtcars %>% select(if_width(2)) #> # A tibble: 32 × 4 #> hp wt vs am #> #> 1 110 2.62 0 1 #> 2 110 2.88 0 1 #> 3 93 2.32 1 1 #> 4 110 3.22 1 0 #> # ℹ 28 more rows mtcars[if_width(2)] #> Error: #> ! `if_width()` must be used within a *selecting* function. #> ℹ See #> for details. if_width(2, vars = names(mtcars)) #> [1] \"hp\" \"wt\" \"vs\" \"am\""},{"path":"https://tidyselect.r-lib.org/dev/articles/tidyselect.html","id":"handling-duplicate-variables","dir":"Articles","previous_headings":"Creating selection helpers","what":"Handling duplicate variables","title":"Implementing tidyselect interfaces","text":"However current implementation if_width() design flaw. doesn’t work properly input duplicate names: Supporting duplicates recommended data frames wild don’t always unique names. Also, tidyselect can used vectors don’t require unique names, might extended allow recoding character vectors future. cases, handling duplicates part normal usage selection helpers. support duplicates recommended return vectors locations selection helpers rather vector names. Fixing if_width() easy: input data frame, user now informed selection contain duplicates: duplicates selected input data frame, expected:","code":"dups <- vctrs::new_data_frame(list(foo = 1, quux = 2, foo = 3)) dups %>% select(if_width(3)) #> foo #> 1 1 if_width <- function(n, vars = peek_vars(fn = \"if_width\")) { which(nchar(vars) == n) } dups %>% select(if_width(3)) #> Error in `select()`: #> ! Names must be unique. #> ✖ These names are duplicated: #> * \"foo\" at locations 1 and 2. as.list(dups) %>% select(if_width(3)) #> $foo #> [1] 1 #> #> $foo #> [1] 3"},{"path":"https://tidyselect.r-lib.org/dev/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Lionel Henry. Author, maintainer. Hadley Wickham. Author. . Copyright holder, funder.","code":""},{"path":"https://tidyselect.r-lib.org/dev/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Henry L, Wickham H (2024). tidyselect: Select Set Strings. R package version 1.2.1.9000, https://github.com/r-lib/tidyselect, https://tidyselect.r-lib.org.","code":"@Manual{, title = {tidyselect: Select from a Set of Strings}, author = {Lionel Henry and Hadley Wickham}, year = {2024}, note = {R package version 1.2.1.9000, https://github.com/r-lib/tidyselect}, url = {https://tidyselect.r-lib.org}, }"},{"path":[]},{"path":"https://tidyselect.r-lib.org/dev/index.html","id":"overview","dir":"","previous_headings":"","what":"Overview","title":"Select from a Set of Strings","text":"tidyselect package backend functions like dplyr::select() dplyr::pull() well several tidyr verbs. allows create selecting verbs consistent tidyverse packages. learn selection syntax user dplyr tidyr, read user-friendly ?language reference. learn implement tidyselect functions, read vignette(\"tidyselect\"). learn exactly tidyselect syntax interpreted, read technical description vignette(\"syntax\").","code":""},{"path":"https://tidyselect.r-lib.org/dev/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Select from a Set of Strings","text":"Generally, tidyselect installed automatically packages need . need install manually reason, can get :","code":"install.packages(\"tidyselect\")"},{"path":"https://tidyselect.r-lib.org/dev/index.html","id":"code-of-conduct","dir":"","previous_headings":"","what":"Code of Conduct","title":"Select from a Set of Strings","text":"Please note tidyselect project released Contributor Code Conduct. contributing project, agree abide terms.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/all_of.html","id":null,"dir":"Reference","previous_headings":"","what":"Select variables from character vectors — all_of","title":"Select variables from character vectors — all_of","text":"selection helpers select variables contained character vector. especially useful programming selecting functions. all_of() strict selection. variables character vector missing, error thrown. any_of() check missing variables. especially useful negative selections, like make sure variable removed. order selected columns determined order vector.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/all_of.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Select variables from character vectors — all_of","text":"","code":"all_of(x) any_of(x, ..., vars = NULL)"},{"path":"https://tidyselect.r-lib.org/dev/reference/all_of.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Select variables from character vectors — all_of","text":"x vector character names numeric locations. ... dots future extensions must empty. vars character vector variable names. supplied, variables taken current selection context (established functions like select() pivot_longer()).","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/all_of.html","id":"examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Select variables from character vectors — all_of","text":"Selection helpers can used functions like dplyr::select() tidyr::pivot_longer(). first attach tidyverse: common names variables vector. refer variables selecting function, use all_of(): variables missing data frame, error: Use any_of() allow missing variables: any_of() especially useful remove variables data frame calling cause error: Supply named vectors all_of() any_of() select rename columns time:","code":"library(tidyverse) # For better printing iris <- as_tibble(iris) vars <- c(\"Sepal.Length\", \"Sepal.Width\") iris[, vars] #> # A tibble: 150 x 2 #> Sepal.Length Sepal.Width #> #> 1 5.1 3.5 #> 2 4.9 3 #> 3 4.7 3.2 #> 4 4.6 3.1 #> # i 146 more rows iris %>% select(all_of(vars)) #> # A tibble: 150 x 2 #> Sepal.Length Sepal.Width #> #> 1 5.1 3.5 #> 2 4.9 3 #> 3 4.7 3.2 #> 4 4.6 3.1 #> # i 146 more rows iris %>% pivot_longer(all_of(vars)) #> # A tibble: 300 x 5 #> Petal.Length Petal.Width Species name value #> #> 1 1.4 0.2 setosa Sepal.Length 5.1 #> 2 1.4 0.2 setosa Sepal.Width 3.5 #> 3 1.4 0.2 setosa Sepal.Length 4.9 #> 4 1.4 0.2 setosa Sepal.Width 3 #> # i 296 more rows starwars %>% select(all_of(vars)) #> Error: #> i In argument: `all_of(vars)`. #> Caused by error in `all_of()`: #> ! Can't subset elements that don't exist. #> x Elements `Sepal.Length` and `Sepal.Width` don't exist. starwars %>% select(any_of(vars)) #> # A tibble: 87 x 0 iris %>% select(-any_of(vars)) #> # A tibble: 150 x 3 #> Petal.Length Petal.Width Species #> #> 1 1.4 0.2 setosa #> 2 1.4 0.2 setosa #> 3 1.3 0.2 setosa #> 4 1.5 0.2 setosa #> # i 146 more rows iris %>% select(-any_of(vars)) %>% select(-any_of(vars)) #> # A tibble: 150 x 3 #> Petal.Length Petal.Width Species #> #> 1 1.4 0.2 setosa #> 2 1.4 0.2 setosa #> 3 1.3 0.2 setosa #> 4 1.5 0.2 setosa #> # i 146 more rows colors <- c(color_of_hair = \"hair_color\", color_of_eyes = \"eye_color\") starwars %>% select(all_of(colors)) #> # A tibble: 87 x 2 #> color_of_hair color_of_eyes #> #> 1 blond blue #> 2 yellow #> 3 red #> 4 none yellow #> # i 83 more rows"},{"path":[]},{"path":"https://tidyselect.r-lib.org/dev/reference/args_tidy_select.html","id":null,"dir":"Reference","previous_headings":"","what":"Argument type: tidy-select — args_tidy_select","title":"Argument type: tidy-select — args_tidy_select","text":"page describes argument modifier indicates argument supports tidy selections. Tidy selection provides concise dialect R selecting variables based names properties. Tidy selection variant tidy evaluation. means inside functions, tidy-select arguments require special attention, described Indirection section . never heard tidy evaluation , start vignette(\"programming\").","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/args_tidy_select.html","id":"overview-of-selection-features","dir":"Reference","previous_headings":"","what":"Overview of selection features","title":"Argument type: tidy-select — args_tidy_select","text":"Tidyverse selections implement dialect R operators make easy select variables: : selecting range consecutive variables. ! taking complement set variables. & | selecting intersection union two sets variables. c() combining selections. addition, can use selection helpers. helpers select specific columns: everything(): Matches variables. last_col(): Select last variable, possibly offset. helpers select variables matching patterns names: starts_with(): Starts prefix. ends_with(): Ends suffix. contains(): Contains literal string. matches(): Matches regular expression. num_range(): Matches numerical range like x01, x02, x03. variables stored character vector: all_of(): Matches variable names character vector. names must present, otherwise --bounds error thrown. any_of(): all_of(), except error thrown names exist. using predicate function: (): Applies function variables selects function returns TRUE.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/args_tidy_select.html","id":"indirection","dir":"Reference","previous_headings":"","what":"Indirection","title":"Argument type: tidy-select — args_tidy_select","text":"two main cases: character vector column names, use all_of() any_of(), depending whether want unknown variable names cause error, e.g. select(df, all_of(vars)), select(df, !any_of(vars)). want user able supply tidyselect specification function argument, embrace function argument, e.g. select(df, {{ vars }}).","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/eval_relocate.html","id":null,"dir":"Reference","previous_headings":"","what":"Evaluate an expression to relocate variables — eval_relocate","title":"Evaluate an expression to relocate variables — eval_relocate","text":"eval_relocate() variant eval_select() moves selection new location. Either can provided specify move selection . powers dplyr::relocate().","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/eval_relocate.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Evaluate an expression to relocate variables — eval_relocate","text":"","code":"eval_relocate( expr, data, ..., before = NULL, after = NULL, strict = TRUE, name_spec = NULL, allow_rename = TRUE, allow_empty = TRUE, allow_predicates = TRUE, before_arg = \"before\", after_arg = \"after\", env = caller_env(), error_arg = NULL, error_call = caller_env() )"},{"path":"https://tidyselect.r-lib.org/dev/reference/eval_relocate.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Evaluate an expression to relocate variables — eval_relocate","text":"expr Defused R code describing selection according tidyselect syntax. data named list, data frame, atomic vector. Technically, data can vector names() \"[[\" implementations. ... dots future extensions must empty. , Defused R code describing selection according tidyselect syntax. selection represents destination selection provided expr. Supplying neither move selection left-hand side. Supplying error. strict TRUE, --bounds errors thrown expr attempts select rename variable exist. FALSE, failed selections renamings ignored. name_spec name specification describing combine propagate names. used case nested c() expressions like c(foo = c(bar = starts_with(\"foo\"))). See name_spec argument vctrs::vec_c() description valid name specs. allow_rename TRUE (default), renaming syntax c(foo = bar) allowed. FALSE, causes error. useful implement purely selective behaviour. allow_empty TRUE (default), ok expr result empty selection. FALSE, error expr yields empty selection. allow_predicates TRUE (default), ok expr use predicates (.e. ()). FALSE, error expr uses predicate. automatically set FALSE data support predicates (determined tidyselect_data_has_predicates()). before_arg, after_arg Argument names . used error messages. env environment evaluate expr. Discarded expr quosure. error_arg Argument names expr. used error messages. (can use \"...\" expr = c(...)). error_call execution environment currently running function, e.g. caller_env(). function mentioned error messages source error. See call argument abort() information.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/eval_relocate.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Evaluate an expression to relocate variables — eval_relocate","text":"named vector numeric locations length equal length(data). position data represented exactly . names normally input data, except user supplied named selections c(). latter case, names reflect new names chosen user.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/eval_relocate.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Evaluate an expression to relocate variables — eval_relocate","text":"","code":"library(rlang) # Interpret defused code as a request to relocate x <- expr(c(mpg, disp)) after <- expr(wt) eval_relocate(x, mtcars, after = after) #> cyl hp drat wt mpg disp qsec vs am gear carb #> 2 4 5 6 1 3 7 8 9 10 11 # Supplying neither `before` nor `after` will move the selection to the # left-hand side eval_relocate(x, mtcars) #> mpg disp cyl hp drat wt qsec vs am gear carb #> 1 3 2 4 5 6 7 8 9 10 11 # Within a function, use `enquo()` to defuse a single argument. # Note that `before` and `after` must also be defused with `enquo()`. my_relocator <- function(x, expr, before = NULL, after = NULL) { eval_relocate(enquo(expr), x, before = enquo(before), after = enquo(after)) } my_relocator(mtcars, vs, before = hp) #> mpg cyl disp vs hp drat wt qsec am gear carb #> 1 2 3 8 4 5 6 7 9 10 11 # Here is an example of using `eval_relocate()` to implement `relocate()`. # Note that the dots are passed on as a defused call to `c(...)`. relocate <- function(.x, ..., .before = NULL, .after = NULL) { pos <- eval_relocate( expr(c(...)), .x, before = enquo(.before), after = enquo(.after) ) set_names(.x[pos], names(pos)) } relocate(mtcars, vs, .before = hp) #> mpg cyl disp vs hp drat wt qsec am gear carb #> Mazda RX4 21.0 6 160.0 0 110 3.90 2.620 16.46 1 4 4 #> Mazda RX4 Wag 21.0 6 160.0 0 110 3.90 2.875 17.02 1 4 4 #> Datsun 710 22.8 4 108.0 1 93 3.85 2.320 18.61 1 4 1 #> Hornet 4 Drive 21.4 6 258.0 1 110 3.08 3.215 19.44 0 3 1 #> Hornet Sportabout 18.7 8 360.0 0 175 3.15 3.440 17.02 0 3 2 #> Valiant 18.1 6 225.0 1 105 2.76 3.460 20.22 0 3 1 #> Duster 360 14.3 8 360.0 0 245 3.21 3.570 15.84 0 3 4 #> Merc 240D 24.4 4 146.7 1 62 3.69 3.190 20.00 0 4 2 #> Merc 230 22.8 4 140.8 1 95 3.92 3.150 22.90 0 4 2 #> Merc 280 19.2 6 167.6 1 123 3.92 3.440 18.30 0 4 4 #> Merc 280C 17.8 6 167.6 1 123 3.92 3.440 18.90 0 4 4 #> Merc 450SE 16.4 8 275.8 0 180 3.07 4.070 17.40 0 3 3 #> Merc 450SL 17.3 8 275.8 0 180 3.07 3.730 17.60 0 3 3 #> Merc 450SLC 15.2 8 275.8 0 180 3.07 3.780 18.00 0 3 3 #> Cadillac Fleetwood 10.4 8 472.0 0 205 2.93 5.250 17.98 0 3 4 #> Lincoln Continental 10.4 8 460.0 0 215 3.00 5.424 17.82 0 3 4 #> Chrysler Imperial 14.7 8 440.0 0 230 3.23 5.345 17.42 0 3 4 #> Fiat 128 32.4 4 78.7 1 66 4.08 2.200 19.47 1 4 1 #> Honda Civic 30.4 4 75.7 1 52 4.93 1.615 18.52 1 4 2 #> Toyota Corolla 33.9 4 71.1 1 65 4.22 1.835 19.90 1 4 1 #> Toyota Corona 21.5 4 120.1 1 97 3.70 2.465 20.01 0 3 1 #> Dodge Challenger 15.5 8 318.0 0 150 2.76 3.520 16.87 0 3 2 #> AMC Javelin 15.2 8 304.0 0 150 3.15 3.435 17.30 0 3 2 #> Camaro Z28 13.3 8 350.0 0 245 3.73 3.840 15.41 0 3 4 #> Pontiac Firebird 19.2 8 400.0 0 175 3.08 3.845 17.05 0 3 2 #> Fiat X1-9 27.3 4 79.0 1 66 4.08 1.935 18.90 1 4 1 #> Porsche 914-2 26.0 4 120.3 0 91 4.43 2.140 16.70 1 5 2 #> Lotus Europa 30.4 4 95.1 1 113 3.77 1.513 16.90 1 5 2 #> Ford Pantera L 15.8 8 351.0 0 264 4.22 3.170 14.50 1 5 4 #> Ferrari Dino 19.7 6 145.0 0 175 3.62 2.770 15.50 1 5 6 #> Maserati Bora 15.0 8 301.0 0 335 3.54 3.570 14.60 1 5 8 #> Volvo 142E 21.4 4 121.0 1 109 4.11 2.780 18.60 1 4 2 relocate(mtcars, starts_with(\"d\"), .after = last_col()) #> mpg cyl hp wt qsec vs am gear carb disp drat #> Mazda RX4 21.0 6 110 2.620 16.46 0 1 4 4 160.0 3.90 #> Mazda RX4 Wag 21.0 6 110 2.875 17.02 0 1 4 4 160.0 3.90 #> Datsun 710 22.8 4 93 2.320 18.61 1 1 4 1 108.0 3.85 #> Hornet 4 Drive 21.4 6 110 3.215 19.44 1 0 3 1 258.0 3.08 #> Hornet Sportabout 18.7 8 175 3.440 17.02 0 0 3 2 360.0 3.15 #> Valiant 18.1 6 105 3.460 20.22 1 0 3 1 225.0 2.76 #> Duster 360 14.3 8 245 3.570 15.84 0 0 3 4 360.0 3.21 #> Merc 240D 24.4 4 62 3.190 20.00 1 0 4 2 146.7 3.69 #> Merc 230 22.8 4 95 3.150 22.90 1 0 4 2 140.8 3.92 #> Merc 280 19.2 6 123 3.440 18.30 1 0 4 4 167.6 3.92 #> Merc 280C 17.8 6 123 3.440 18.90 1 0 4 4 167.6 3.92 #> Merc 450SE 16.4 8 180 4.070 17.40 0 0 3 3 275.8 3.07 #> Merc 450SL 17.3 8 180 3.730 17.60 0 0 3 3 275.8 3.07 #> Merc 450SLC 15.2 8 180 3.780 18.00 0 0 3 3 275.8 3.07 #> Cadillac Fleetwood 10.4 8 205 5.250 17.98 0 0 3 4 472.0 2.93 #> Lincoln Continental 10.4 8 215 5.424 17.82 0 0 3 4 460.0 3.00 #> Chrysler Imperial 14.7 8 230 5.345 17.42 0 0 3 4 440.0 3.23 #> Fiat 128 32.4 4 66 2.200 19.47 1 1 4 1 78.7 4.08 #> Honda Civic 30.4 4 52 1.615 18.52 1 1 4 2 75.7 4.93 #> Toyota Corolla 33.9 4 65 1.835 19.90 1 1 4 1 71.1 4.22 #> Toyota Corona 21.5 4 97 2.465 20.01 1 0 3 1 120.1 3.70 #> Dodge Challenger 15.5 8 150 3.520 16.87 0 0 3 2 318.0 2.76 #> AMC Javelin 15.2 8 150 3.435 17.30 0 0 3 2 304.0 3.15 #> Camaro Z28 13.3 8 245 3.840 15.41 0 0 3 4 350.0 3.73 #> Pontiac Firebird 19.2 8 175 3.845 17.05 0 0 3 2 400.0 3.08 #> Fiat X1-9 27.3 4 66 1.935 18.90 1 1 4 1 79.0 4.08 #> Porsche 914-2 26.0 4 91 2.140 16.70 0 1 5 2 120.3 4.43 #> Lotus Europa 30.4 4 113 1.513 16.90 1 1 5 2 95.1 3.77 #> Ford Pantera L 15.8 8 264 3.170 14.50 0 1 5 4 351.0 4.22 #> Ferrari Dino 19.7 6 175 2.770 15.50 0 1 5 6 145.0 3.62 #> Maserati Bora 15.0 8 335 3.570 14.60 0 1 5 8 301.0 3.54 #> Volvo 142E 21.4 4 109 2.780 18.60 1 1 4 2 121.0 4.11"},{"path":"https://tidyselect.r-lib.org/dev/reference/eval_select.html","id":null,"dir":"Reference","previous_headings":"","what":"Evaluate an expression with tidyselect semantics — eval_rename","title":"Evaluate an expression with tidyselect semantics — eval_rename","text":"eval_select() eval_rename() evaluate defused R code (.e. quoted expressions) according special rules tidyselect syntax. power functions like dplyr::select(), dplyr::rename(), tidyr::pivot_longer(). See Get started vignette learn use eval_select() eval_rename() packages.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/eval_select.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Evaluate an expression with tidyselect semantics — eval_rename","text":"","code":"eval_rename( expr, data, env = caller_env(), ..., strict = TRUE, name_spec = NULL, allow_predicates = TRUE, error_call = caller_env() ) eval_select( expr, data, env = caller_env(), ..., include = NULL, exclude = NULL, strict = TRUE, name_spec = NULL, allow_rename = TRUE, allow_empty = TRUE, allow_predicates = TRUE, error_arg = NULL, error_call = caller_env() )"},{"path":"https://tidyselect.r-lib.org/dev/reference/eval_select.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Evaluate an expression with tidyselect semantics — eval_rename","text":"expr Defused R code describing selection according tidyselect syntax. data named list, data frame, atomic vector. Technically, data can vector names() \"[[\" implementations. env environment evaluate expr. Discarded expr quosure. ... dots future extensions must empty. strict TRUE, --bounds errors thrown expr attempts select rename variable exist. FALSE, failed selections renamings ignored. name_spec name specification describing combine propagate names. used case nested c() expressions like c(foo = c(bar = starts_with(\"foo\"))). See name_spec argument vctrs::vec_c() description valid name specs. allow_predicates TRUE (default), ok expr use predicates (.e. ()). FALSE, error expr uses predicate. automatically set FALSE data support predicates (determined tidyselect_data_has_predicates()). error_call execution environment currently running function, e.g. caller_env(). function mentioned error messages source error. See call argument abort() information. include, exclude Character vector column names always include exclude selection. allow_rename TRUE (default), renaming syntax c(foo = bar) allowed. FALSE, causes error. useful implement purely selective behaviour. allow_empty TRUE (default), ok expr result empty selection. FALSE, error expr yields empty selection. error_arg Argument names expr. used error messages. (can use \"...\" expr = c(...)).","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/eval_select.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Evaluate an expression with tidyselect semantics — eval_rename","text":"named vector numeric locations, one selected elements. names normally input data, except user supplied named selections c(). latter case, names reflect new names chosen user. given element may selected multiple times different names, case vector might contain duplicate locations.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/eval_select.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Evaluate an expression with tidyselect semantics — eval_rename","text":"select rename variants take types inputs type return value. However eval_rename() extra constraints. requires named inputs, fail data frame column renamed another existing column name. See selecting versus renaming section syntax vignette description differences.","code":""},{"path":[]},{"path":"https://tidyselect.r-lib.org/dev/reference/eval_select.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Evaluate an expression with tidyselect semantics — eval_rename","text":"","code":"library(rlang) # Interpret defused code as selection: x <- expr(mpg:cyl) eval_select(x, mtcars) #> mpg cyl #> 1 2 # Interpret defused code as a renaming selection. All inputs must # be named within `c()`: try(eval_rename(expr(mpg), mtcars)) #> Error in eval(expr, envir) : All renaming inputs must be named. eval_rename(expr(c(foo = mpg)), mtcars) #> foo #> 1 # Within a function, use `enquo()` to defuse one argument: my_function <- function(x, expr) { eval_select(enquo(expr), x) } # If your function takes dots, evaluate a defused call to `c(...)` # with `expr(c(...))`: my_function <- function(.x, ...) { eval_select(expr(c(...)), .x) } # If your function takes dots and a named argument, use `{{ }}` # inside the defused expression to tunnel it inside the tidyselect DSL: my_function <- function(.x, .expr, ...) { eval_select(expr(c({{ .expr }}, ...)), .x) } # Note that the trick above works because `expr({{ arg }})` is the # same as `enquo(arg)`. # Supply `error_arg` to improve the error message in case of # unexpected empty selection: select_not_empty <- function(x, cols) { eval_select(expr = enquo(cols), data = x, allow_empty = FALSE, error_arg = \"cols\") } try(select_not_empty(mtcars, cols = starts_with(\"vs2\"))) #> Error in select_not_empty(mtcars, cols = starts_with(\"vs2\")) : #> `cols` must select at least one column. # The evaluators return a named vector of locations. Here are # examples of using these location vectors to implement `select()` # and `rename()`: select <- function(.x, ...) { pos <- eval_select(expr(c(...)), .x) set_names(.x[pos], names(pos)) } rename <- function(.x, ...) { pos <- eval_rename(expr(c(...)), .x) names(.x)[pos] <- names(pos) .x } select(mtcars, mpg:cyl) #> mpg cyl #> Mazda RX4 21.0 6 #> Mazda RX4 Wag 21.0 6 #> Datsun 710 22.8 4 #> Hornet 4 Drive 21.4 6 #> Hornet Sportabout 18.7 8 #> Valiant 18.1 6 #> Duster 360 14.3 8 #> Merc 240D 24.4 4 #> Merc 230 22.8 4 #> Merc 280 19.2 6 #> Merc 280C 17.8 6 #> Merc 450SE 16.4 8 #> Merc 450SL 17.3 8 #> Merc 450SLC 15.2 8 #> Cadillac Fleetwood 10.4 8 #> Lincoln Continental 10.4 8 #> Chrysler Imperial 14.7 8 #> Fiat 128 32.4 4 #> Honda Civic 30.4 4 #> Toyota Corolla 33.9 4 #> Toyota Corona 21.5 4 #> Dodge Challenger 15.5 8 #> AMC Javelin 15.2 8 #> Camaro Z28 13.3 8 #> Pontiac Firebird 19.2 8 #> Fiat X1-9 27.3 4 #> Porsche 914-2 26.0 4 #> Lotus Europa 30.4 4 #> Ford Pantera L 15.8 8 #> Ferrari Dino 19.7 6 #> Maserati Bora 15.0 8 #> Volvo 142E 21.4 4 rename(mtcars, foo = mpg) #> foo cyl disp hp drat wt qsec vs am gear carb #> Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4 #> Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4 #> Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1 #> Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1 #> Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2 #> Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1 #> Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4 #> Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2 #> Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4 2 #> Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4 #> Merc 280C 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4 4 #> Merc 450SE 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3 #> Merc 450SL 17.3 8 275.8 180 3.07 3.730 17.60 0 0 3 3 #> Merc 450SLC 15.2 8 275.8 180 3.07 3.780 18.00 0 0 3 3 #> Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3 4 #> Lincoln Continental 10.4 8 460.0 215 3.00 5.424 17.82 0 0 3 4 #> Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3 4 #> Fiat 128 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4 1 #> Honda Civic 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2 #> Toyota Corolla 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1 #> Toyota Corona 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3 1 #> Dodge Challenger 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3 2 #> AMC Javelin 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3 2 #> Camaro Z28 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3 4 #> Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2 #> Fiat X1-9 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4 1 #> Porsche 914-2 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2 #> Lotus Europa 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5 2 #> Ford Pantera L 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5 4 #> Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6 #> Maserati Bora 15.0 8 301.0 335 3.54 3.570 14.60 0 1 5 8 #> Volvo 142E 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2"},{"path":"https://tidyselect.r-lib.org/dev/reference/everything.html","id":null,"dir":"Reference","previous_headings":"","what":"Select all variables or the last variable — everything","title":"Select all variables or the last variable — everything","text":"functions selection helpers. everything() selects variable. also useful combination tidyselect operators. last_col() selects last variable.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/everything.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Select all variables or the last variable — everything","text":"","code":"everything(vars = NULL) last_col(offset = 0L, vars = NULL)"},{"path":"https://tidyselect.r-lib.org/dev/reference/everything.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Select all variables or the last variable — everything","text":"vars character vector variable names. supplied, variables taken current selection context (established functions like select() pivot_longer()). offset Set n select nth var end.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/everything.html","id":"examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Select all variables or the last variable — everything","text":"Selection helpers can used functions like dplyr::select() tidyr::pivot_longer(). first attach tidyverse: Use everything() select variables: Use last_col() select last variable: Supply offset n select variable located n positions end:","code":"library(tidyverse) # For better printing iris <- as_tibble(iris) mtcars <- as_tibble(mtcars) iris %>% select(everything()) #> # A tibble: 150 x 5 #> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> #> 1 5.1 3.5 1.4 0.2 setosa #> 2 4.9 3 1.4 0.2 setosa #> 3 4.7 3.2 1.3 0.2 setosa #> 4 4.6 3.1 1.5 0.2 setosa #> # i 146 more rows mtcars %>% pivot_longer(everything()) #> # A tibble: 352 x 2 #> name value #> #> 1 mpg 21 #> 2 cyl 6 #> 3 disp 160 #> 4 hp 110 #> # i 348 more rows iris %>% select(last_col()) #> # A tibble: 150 x 1 #> Species #> #> 1 setosa #> 2 setosa #> 3 setosa #> 4 setosa #> # i 146 more rows mtcars %>% pivot_longer(last_col()) #> # A tibble: 32 x 12 #> mpg cyl disp hp drat wt qsec vs am gear name value #> #> 1 21 6 160 110 3.9 2.62 16.5 0 1 4 carb 4 #> 2 21 6 160 110 3.9 2.88 17.0 0 1 4 carb 4 #> 3 22.8 4 108 93 3.85 2.32 18.6 1 1 4 carb 1 #> 4 21.4 6 258 110 3.08 3.22 19.4 1 0 3 carb 1 #> # i 28 more rows mtcars %>% select(1:last_col(5)) #> # A tibble: 32 x 6 #> mpg cyl disp hp drat wt #> #> 1 21 6 160 110 3.9 2.62 #> 2 21 6 160 110 3.9 2.88 #> 3 22.8 4 108 93 3.85 2.32 #> 4 21.4 6 258 110 3.08 3.22 #> # i 28 more rows"},{"path":[]},{"path":[]},{"path":"https://tidyselect.r-lib.org/dev/reference/faq-external-vector.html","id":"ambiguity-between-columns-and-external-variables","dir":"Reference","previous_headings":"","what":"Ambiguity between columns and external variables","title":"FAQ - Note: Using an external vector in selections is ambiguous — faq-external-vector","text":"selecting functions like dplyr::select() tidyr::pivot_longer(), can refer variables name: historical reasons, also possible refer external vector variable names. get correct result, warning informing selecting external variable ambiguous clear whether want data frame column external object. decided deprecate particular approach using external vectors introduce ambiguity. Imagine data frame contains column name external variable. different objects isn’t problem context forces specific find vars: selection context however, column wins:","code":"mtcars %>% select(cyl, am, vs) #> # A tibble: 32 x 3 #> cyl am vs #> #> 1 6 1 0 #> 2 6 1 0 #> 3 4 1 1 #> 4 6 0 1 #> # i 28 more rows mtcars %>% select(mpg:disp) #> # A tibble: 32 x 3 #> mpg cyl disp #> #> 1 21 6 160 #> 2 21 6 160 #> 3 22.8 4 108 #> 4 21.4 6 258 #> # i 28 more rows vars <- c(\"cyl\", \"am\", \"vs\") result <- mtcars %>% select(vars) #> Warning: Using an external vector in selections was deprecated in tidyselect 1.1.0. #> i Please use `all_of()` or `any_of()` instead. #> i See . #> This warning is displayed once every 8 hours. #> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was #> generated. some_df <- mtcars[1:4, ] some_df$vars <- 1:nrow(some_df) vars #> [1] \"cyl\" \"am\" \"vs\" some_df$vars #> [1] 1 2 3 4 some_df %>% select(vars) #> # A tibble: 4 x 1 #> vars #> #> 1 1 #> 2 2 #> 3 3 #> 4 4"},{"path":"https://tidyselect.r-lib.org/dev/reference/faq-external-vector.html","id":"fixing-the-ambiguity","dir":"Reference","previous_headings":"","what":"Fixing the ambiguity","title":"FAQ - Note: Using an external vector in selections is ambiguous — faq-external-vector","text":"make selection code robust silence message, use all_of() force external vector: information comments , please see Github issue tracking deprecation process.","code":"some_df %>% select(all_of(vars)) #> # A tibble: 4 x 3 #> cyl am vs #> #> 1 6 1 0 #> 2 6 1 0 #> 3 4 1 1 #> 4 6 0 1"},{"path":"https://tidyselect.r-lib.org/dev/reference/faq-selection-context.html","id":null,"dir":"Reference","previous_headings":"","what":"FAQ - Error: Must be used within a selecting function — faq-selection-context","title":"FAQ - Error: Must be used within a selecting function — faq-selection-context","text":"Functions like starts_with(), contains() matches() selection helpers work selection context, e.g. dplyr::select() cols argument tidyr::pivot_longer(). Using selection helper anywhere else results error: see error, may used selection helper wrong place, possibly result typo (e.g. misplaced comma wrong argument name). Alternatively, may deliberately trying reduce duplication code extracting selection variable: make work ’ll need two things: Wrap whole thing function Use any_of() all_of() instead bare variable names","code":"starts_with(\"foo\") #> Error: #> ! `starts_with()` must be used within a *selecting* function. #> i See for #> details. mtcars[contains(\"foo\")] #> Error: #> ! `contains()` must be used within a *selecting* function. #> i See for #> details. subset(mtcars, select = matches(\"foo\")) #> Error: #> ! `matches()` must be used within a *selecting* function. #> i See for #> details. my_vars <- c(name, species, ends_with(\"color\")) #> Error: object 'name' not found my_vars <- function() { c(any_of(c(\"name\", \"species\")), ends_with(\"color\")) } dplyr::select(starwars, my_vars()) #> # A tibble: 87 x 5 #> name species hair_color skin_color eye_color #> #> 1 Luke Skywalker Human blond fair blue #> 2 C-3PO Droid gold yellow #> 3 R2-D2 Droid white, blue red #> 4 Darth Vader Human none white yellow #> # i 83 more rows"},{"path":[]},{"path":"https://tidyselect.r-lib.org/dev/reference/language.html","id":"overview-of-selection-features-","dir":"Reference","previous_headings":"","what":"Overview of selection features:","title":"Selection language — language","text":"Tidyverse selections implement dialect R operators make easy select variables: : selecting range consecutive variables. ! taking complement set variables. & | selecting intersection union two sets variables. c() combining selections. addition, can use selection helpers. helpers select specific columns: everything(): Matches variables. last_col(): Select last variable, possibly offset. helpers select variables matching patterns names: starts_with(): Starts prefix. ends_with(): Ends suffix. contains(): Contains literal string. matches(): Matches regular expression. num_range(): Matches numerical range like x01, x02, x03. variables stored character vector: all_of(): Matches variable names character vector. names must present, otherwise --bounds error thrown. any_of(): all_of(), except error thrown names exist. using predicate function: (): Applies function variables selects function returns TRUE.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/language.html","id":"simple-examples","dir":"Reference","previous_headings":"","what":"Simple examples","title":"Selection language — language","text":"show usage basic selection operators. See specific help pages learn helpers like starts_with(). selection language can used functions like dplyr::select() tidyr::pivot_longer(). first attach tidyverse: Select variables name: Select multiple variables separating commas. Note order columns determined order inputs: Functions like tidyr::pivot_longer() take variables dots. case use c() select multiple variables:","code":"library(tidyverse) # For better printing iris <- as_tibble(iris) starwars %>% select(height) #> # A tibble: 87 x 1 #> height #> #> 1 172 #> 2 167 #> 3 96 #> 4 202 #> # i 83 more rows iris %>% pivot_longer(Sepal.Length) #> # A tibble: 150 x 6 #> Sepal.Width Petal.Length Petal.Width Species name value #> #> 1 3.5 1.4 0.2 setosa Sepal.Length 5.1 #> 2 3 1.4 0.2 setosa Sepal.Length 4.9 #> 3 3.2 1.3 0.2 setosa Sepal.Length 4.7 #> 4 3.1 1.5 0.2 setosa Sepal.Length 4.6 #> # i 146 more rows starwars %>% select(homeworld, height, mass) #> # A tibble: 87 x 3 #> homeworld height mass #> #> 1 Tatooine 172 77 #> 2 Tatooine 167 75 #> 3 Naboo 96 32 #> 4 Tatooine 202 136 #> # i 83 more rows iris %>% pivot_longer(c(Sepal.Length, Petal.Length)) #> # A tibble: 300 x 5 #> Sepal.Width Petal.Width Species name value #> #> 1 3.5 0.2 setosa Sepal.Length 5.1 #> 2 3.5 0.2 setosa Petal.Length 1.4 #> 3 3 0.2 setosa Sepal.Length 4.9 #> 4 3 0.2 setosa Petal.Length 1.4 #> # i 296 more rows"},{"path":"https://tidyselect.r-lib.org/dev/reference/language.html","id":"operators-","dir":"Reference","previous_headings":"","what":"Operators:","title":"Selection language — language","text":": operator selects range consecutive variables: ! operator negates selection: & | take intersection union two selections: take difference two selections, combine & ! operators:","code":"starwars %>% select(name:mass) #> # A tibble: 87 x 3 #> name height mass #> #> 1 Luke Skywalker 172 77 #> 2 C-3PO 167 75 #> 3 R2-D2 96 32 #> 4 Darth Vader 202 136 #> # i 83 more rows starwars %>% select(!(name:mass)) #> # A tibble: 87 x 11 #> hair_color skin_color eye_color birth_year sex gender homeworld species #> #> 1 blond fair blue 19 male masculine Tatooine Human #> 2 gold yellow 112 none masculine Tatooine Droid #> 3 white, blue red 33 none masculine Naboo Droid #> 4 none white yellow 41.9 male masculine Tatooine Human #> # i 83 more rows #> # i 3 more variables: films , vehicles , starships iris %>% select(!c(Sepal.Length, Petal.Length)) #> # A tibble: 150 x 3 #> Sepal.Width Petal.Width Species #> #> 1 3.5 0.2 setosa #> 2 3 0.2 setosa #> 3 3.2 0.2 setosa #> 4 3.1 0.2 setosa #> # i 146 more rows iris %>% select(!ends_with(\"Width\")) #> # A tibble: 150 x 3 #> Sepal.Length Petal.Length Species #> #> 1 5.1 1.4 setosa #> 2 4.9 1.4 setosa #> 3 4.7 1.3 setosa #> 4 4.6 1.5 setosa #> # i 146 more rows iris %>% select(starts_with(\"Petal\") & ends_with(\"Width\")) #> # A tibble: 150 x 1 #> Petal.Width #> #> 1 0.2 #> 2 0.2 #> 3 0.2 #> 4 0.2 #> # i 146 more rows iris %>% select(starts_with(\"Petal\") | ends_with(\"Width\")) #> # A tibble: 150 x 3 #> Petal.Length Petal.Width Sepal.Width #> #> 1 1.4 0.2 3.5 #> 2 1.4 0.2 3 #> 3 1.3 0.2 3.2 #> 4 1.5 0.2 3.1 #> # i 146 more rows iris %>% select(starts_with(\"Petal\") & !ends_with(\"Width\")) #> # A tibble: 150 x 1 #> Petal.Length #> #> 1 1.4 #> 2 1.4 #> 3 1.3 #> 4 1.5 #> # i 146 more rows"},{"path":"https://tidyselect.r-lib.org/dev/reference/language.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Selection language — language","text":"order selected columns determined inputs. all_of(c(\"foo\", \"bar\")) selects \"foo\" first. c(starts_with(\"c\"), starts_with(\"d\")) selects columns starting \"c\" first, columns starting \"d\".","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/one_of.html","id":null,"dir":"Reference","previous_headings":"","what":"Superseded selection helpers — one_of","title":"Superseded selection helpers — one_of","text":"one_of() superseded favour precise any_of() all_of() selectors.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/one_of.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Superseded selection helpers — one_of","text":"","code":"one_of(..., .vars = NULL)"},{"path":"https://tidyselect.r-lib.org/dev/reference/one_of.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Superseded selection helpers — one_of","text":"... One character vectors. .vars character vector variable names. called inside selecting functions like dplyr::select() automatically set names table.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/peek_vars.html","id":null,"dir":"Reference","previous_headings":"","what":"Peek at variables in the selection context — peek_vars","title":"Peek at variables in the selection context — peek_vars","text":"peek_vars() returns vector names variables currently available selection. peek_data() returns whole input vector (available eval_select()). Read Get started examples create selection helpers peek_vars(). variable names selection context registered automatically eval_select() eval_rename() duration evaluation. peek_vars() glue connects selection helpers current selection context.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/peek_vars.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Peek at variables in the selection context — peek_vars","text":"","code":"peek_vars(..., fn = NULL) peek_data(..., fn = NULL)"},{"path":"https://tidyselect.r-lib.org/dev/reference/peek_vars.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Peek at variables in the selection context — peek_vars","text":"... dots future extensions must empty. fn name function use error messages helper used wrong context. supplied, generic error message used instead.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/poke_vars.html","id":null,"dir":"Reference","previous_headings":"","what":"Replace or get current variables — poke_vars","title":"Replace or get current variables — poke_vars","text":"Variables made available select helpers registering special placeholder. scoped_vars() changes current variables sets function exit hook automatically restores previous variables current function returns. with_vars() takes expression evaluated variable context. poke_vars() changes contents placeholder new set variables. returns previous variables invisibly responsibility restore done. expert use . peek_vars() returns variables currently registered. has_vars() returns TRUE variable context set, FALSE otherwise.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/poke_vars.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Replace or get current variables — poke_vars","text":"","code":"poke_vars(vars) scoped_vars(vars, frame = caller_env()) with_vars(vars, expr) has_vars()"},{"path":"https://tidyselect.r-lib.org/dev/reference/poke_vars.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Replace or get current variables — poke_vars","text":"vars character vector variable names. frame frame environment exit hook restoring old variables registered. expr expression evaluated within variable context.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/poke_vars.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Replace or get current variables — poke_vars","text":"poke_vars() scoped_vars(), old variables invisibly. peek_vars(), variables currently registered.","code":""},{"path":[]},{"path":"https://tidyselect.r-lib.org/dev/reference/poke_vars.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Replace or get current variables — poke_vars","text":"","code":"poke_vars(letters) peek_vars() #> [1] \"a\" \"b\" \"c\" \"d\" \"e\" \"f\" \"g\" \"h\" \"i\" \"j\" \"k\" \"l\" \"m\" \"n\" \"o\" \"p\" \"q\" #> [18] \"r\" \"s\" \"t\" \"u\" \"v\" \"w\" \"x\" \"y\" \"z\" # Now that the variables are registered, the helpers can figure out # the locations of elements within the variable vector: all_of(c(\"d\", \"z\")) #> [1] 4 26 # In a function be sure to restore the previous variables. An exit # hook is the best way to do it: fn <- function(vars) { old <- poke_vars(vars) on.exit(poke_vars(old)) all_of(\"d\") } fn(letters) #> [1] 4 fn(letters[3:5]) #> [1] 2 # The previous variables are still registered after fn() was # called: peek_vars() #> [1] \"a\" \"b\" \"c\" \"d\" \"e\" \"f\" \"g\" \"h\" \"i\" \"j\" \"k\" \"l\" \"m\" \"n\" \"o\" \"p\" \"q\" #> [18] \"r\" \"s\" \"t\" \"u\" \"v\" \"w\" \"x\" \"y\" \"z\" # It is recommended to use the scoped variant as it restores the # state automatically when the function returns: fn <- function(vars) { scoped_vars(vars) starts_with(\"r\") } fn(c(\"red\", \"blue\", \"rose\")) #> [1] 1 3 # The with_vars() helper makes it easy to pass an expression that # should be evaluated in a variable context. Thanks to lazy # evaluation, you can just pass the expression argument from your # wrapper to with_vars(): fn <- function(expr) { vars <- c(\"red\", \"blue\", \"rose\") with_vars(vars, expr) } fn(starts_with(\"r\")) #> [1] 1 3"},{"path":"https://tidyselect.r-lib.org/dev/reference/reexports.html","id":null,"dir":"Reference","previous_headings":"","what":"Objects exported from other packages — reexports","title":"Objects exported from other packages — reexports","text":"objects imported packages. Follow links see documentation. rlang enquo, quo, quo_name, quos","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/starts_with.html","id":null,"dir":"Reference","previous_headings":"","what":"Select variables that match a pattern — starts_with","title":"Select variables that match a pattern — starts_with","text":"selection helpers match variables according given pattern. starts_with(): Starts exact prefix. ends_with(): Ends exact suffix. contains(): Contains literal string. matches(): Matches regular expression. num_range(): Matches numerical range like x01, x02, x03.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/starts_with.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Select variables that match a pattern — starts_with","text":"","code":"starts_with(match, ignore.case = TRUE, vars = NULL) ends_with(match, ignore.case = TRUE, vars = NULL) contains(match, ignore.case = TRUE, vars = NULL) matches(match, ignore.case = TRUE, perl = TRUE, vars = NULL) num_range( prefix, range, suffix = \"\", width = NULL, ..., cross = FALSE, vars = NULL )"},{"path":"https://tidyselect.r-lib.org/dev/reference/starts_with.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Select variables that match a pattern — starts_with","text":"match character vector. length > 1, union matches taken. starts_with(), ends_with(), contains() exact match. matches() regular expression, can stringr pattern. ignore.case TRUE, default, ignores case matching names. vars character vector variable names. supplied, variables taken current selection context (established functions like select() pivot_longer()). perl Perl-compatible regexps used? prefix, suffix prefix/suffix added /numeric range. range sequence integers, like 1:5. width Optionally, \"width\" numeric range. example, range 2 gives \"01\", range three \"001\", etc. ... dots future extensions must empty. cross Whether take cartesian product prefix, range, suffix. FALSE, default, arguments recycled using tidyverse rules.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/starts_with.html","id":"examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Select variables that match a pattern — starts_with","text":"Selection helpers can used functions like dplyr::select() tidyr::pivot_longer(). first attach tidyverse: starts_with() selects variables matching prefix ends_with() matches suffix: can supply multiple prefixes suffixes. Note order variables depends order suffixes prefixes: contains() selects columns whose names contain word: starts_with(), ends_with(), contains() use regular expressions. select regexp use matches(): starts_with() selects variables starting prefix. select range, use num_range(). Compare:","code":"library(tidyverse) # For better printing iris <- as_tibble(iris) iris %>% select(starts_with(\"Sepal\")) #> # A tibble: 150 x 2 #> Sepal.Length Sepal.Width #> #> 1 5.1 3.5 #> 2 4.9 3 #> 3 4.7 3.2 #> 4 4.6 3.1 #> # i 146 more rows iris %>% select(ends_with(\"Width\")) #> # A tibble: 150 x 2 #> Sepal.Width Petal.Width #> #> 1 3.5 0.2 #> 2 3 0.2 #> 3 3.2 0.2 #> 4 3.1 0.2 #> # i 146 more rows iris %>% select(starts_with(c(\"Petal\", \"Sepal\"))) #> # A tibble: 150 x 4 #> Petal.Length Petal.Width Sepal.Length Sepal.Width #> #> 1 1.4 0.2 5.1 3.5 #> 2 1.4 0.2 4.9 3 #> 3 1.3 0.2 4.7 3.2 #> 4 1.5 0.2 4.6 3.1 #> # i 146 more rows iris %>% select(ends_with(c(\"Width\", \"Length\"))) #> # A tibble: 150 x 4 #> Sepal.Width Petal.Width Sepal.Length Petal.Length #> #> 1 3.5 0.2 5.1 1.4 #> 2 3 0.2 4.9 1.4 #> 3 3.2 0.2 4.7 1.3 #> 4 3.1 0.2 4.6 1.5 #> # i 146 more rows iris %>% select(contains(\"al\")) #> # A tibble: 150 x 4 #> Sepal.Length Sepal.Width Petal.Length Petal.Width #> #> 1 5.1 3.5 1.4 0.2 #> 2 4.9 3 1.4 0.2 #> 3 4.7 3.2 1.3 0.2 #> 4 4.6 3.1 1.5 0.2 #> # i 146 more rows # [pt] is matched literally: iris %>% select(contains(\"[pt]al\")) #> # A tibble: 150 x 0 # [pt] is interpreted as a regular expression iris %>% select(matches(\"[pt]al\")) #> # A tibble: 150 x 4 #> Sepal.Length Sepal.Width Petal.Length Petal.Width #> #> 1 5.1 3.5 1.4 0.2 #> 2 4.9 3 1.4 0.2 #> 3 4.7 3.2 1.3 0.2 #> 4 4.6 3.1 1.5 0.2 #> # i 146 more rows billboard %>% select(starts_with(\"wk\")) #> # A tibble: 317 x 76 #> wk1 wk2 wk3 wk4 wk5 wk6 wk7 wk8 wk9 wk10 wk11 wk12 wk13 #> #> 1 87 82 72 77 87 94 99 NA NA NA NA NA NA #> 2 91 87 92 NA NA NA NA NA NA NA NA NA NA #> 3 81 70 68 67 66 57 54 53 51 51 51 51 47 #> 4 76 76 72 69 67 65 55 59 62 61 61 59 61 #> # i 313 more rows #> # i 63 more variables: wk14 , wk15 , wk16 , wk17 , #> # wk18 , wk19 , wk20 , wk21 , ... billboard %>% select(num_range(\"wk\", 10:15)) #> # A tibble: 317 x 6 #> wk10 wk11 wk12 wk13 wk14 wk15 #> #> 1 NA NA NA NA NA NA #> 2 NA NA NA NA NA NA #> 3 51 51 51 47 44 38 #> 4 61 61 59 61 66 72 #> # i 313 more rows"},{"path":[]},{"path":"https://tidyselect.r-lib.org/dev/reference/tidyselect-package.html","id":null,"dir":"Reference","previous_headings":"","what":"tidyselect: Select from a Set of Strings — tidyselect-package","title":"tidyselect: Select from a Set of Strings — tidyselect-package","text":"backend selecting functions 'tidyverse'. makes easy implement select-like functions packages way consistent 'tidyverse' interfaces selection.","code":""},{"path":[]},{"path":"https://tidyselect.r-lib.org/dev/reference/tidyselect-package.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"tidyselect: Select from a Set of Strings — tidyselect-package","text":"Maintainer: Lionel Henry lionel@posit.co Authors: Hadley Wickham hadley@posit.co contributors: Posit Software, PBC [copyright holder, funder]","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/tidyselect_data_proxy.html","id":null,"dir":"Reference","previous_headings":"","what":"tidyselect methods for custom types — tidyselect_data_proxy","title":"tidyselect methods for custom types — tidyselect_data_proxy","text":"tidyselect_data_proxy() returns data frame. tidyselect_data_has_predicates() returns TRUE FALSE support predicate functions, return 0-row data frame tidyselect_data_proxy() FALSE tidyselect_data_has_predicates().","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/tidyselect_data_proxy.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"tidyselect methods for custom types — tidyselect_data_proxy","text":"","code":"tidyselect_data_proxy(x) tidyselect_data_has_predicates(x)"},{"path":"https://tidyselect.r-lib.org/dev/reference/tidyselect_data_proxy.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"tidyselect methods for custom types — tidyselect_data_proxy","text":"x data-frame like object passed eval_select(), eval_rename(), friends.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/vars_pull.html","id":null,"dir":"Reference","previous_headings":"","what":"Select variable — vars_pull","title":"Select variable — vars_pull","text":"function powers dplyr::pull() various functions tidyr package. similar vars_select() returns one column name slightly different semantics: allows negative numbers select columns end.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/vars_pull.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Select variable — vars_pull","text":"","code":"vars_pull( vars, var = -1, error_call = caller_env(), error_arg = caller_arg(var) )"},{"path":"https://tidyselect.r-lib.org/dev/reference/vars_pull.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Select variable — vars_pull","text":"vars character vector existing column names. var variable specified : literal variable name positive integer, giving position counting left negative integer, giving position counting right. default returns last column (assumption column created recently). argument taken expression supports quasiquotation (can unquote column names column locations). error_call execution environment currently running function, e.g. caller_env(). function mentioned error messages source error. See call argument abort() information. error_arg argument name string. argument mentioned error messages input origin problem.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/vars_pull.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Select variable — vars_pull","text":"selected column name unnamed string.","code":""},{"path":[]},{"path":"https://tidyselect.r-lib.org/dev/reference/vars_pull.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Select variable — vars_pull","text":"","code":"# It takes its argument by expression: vars_pull(letters, c) #> [1] \"c\" # Negative numbers select from the end: vars_pull(letters, -3) #> [1] \"x\" # You can unquote variables: var <- 10 vars_pull(letters, !!var) #> [1] \"j\""},{"path":"https://tidyselect.r-lib.org/dev/reference/vars_select.html","id":null,"dir":"Reference","previous_headings":"","what":"Select or rename variables — vars_select","title":"Select or rename variables — vars_select","text":"Please use eval_select() eval_rename() instead. See vignette(\"tidyselect\") get started.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/vars_select.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Select or rename variables — vars_select","text":"","code":"vars_select( .vars, ..., .include = character(), .exclude = character(), .strict = TRUE ) vars_rename(.vars, ..., .strict = TRUE)"},{"path":"https://tidyselect.r-lib.org/dev/reference/vars_select.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Select or rename variables — vars_select","text":".vars character vector existing column names. ... Selection inputs. See help selection helpers. .include, .exclude Character vector column names always include/exclude. .strict TRUE, throw error attempt select rename variable exist.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/vars_select.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Select or rename variables — vars_select","text":"named character vector. Values existing column names, names new names.","code":""},{"path":[]},{"path":"https://tidyselect.r-lib.org/dev/reference/vars_select_helpers.html","id":null,"dir":"Reference","previous_headings":"","what":"List of selection helpers — vars_select_helpers","title":"List of selection helpers — vars_select_helpers","text":"list contains selection helpers exported tidyselect. useful wanted embed helpers API without track addition new helpers tidyselect. However selection helpers now always embedded DSL.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/vars_select_helpers.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"List of selection helpers — vars_select_helpers","text":"","code":"vars_select_helpers"},{"path":"https://tidyselect.r-lib.org/dev/reference/vars_select_helpers.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"List of selection helpers — vars_select_helpers","text":"object class list length 11.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/where.html","id":null,"dir":"Reference","previous_headings":"","what":"Select variables with a function — where","title":"Select variables with a function — where","text":"selection helper selects variables function returns TRUE.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/where.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Select variables with a function — where","text":"","code":"where(fn)"},{"path":"https://tidyselect.r-lib.org/dev/reference/where.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Select variables with a function — where","text":"fn function returns TRUE FALSE (technically, predicate function). Can also purrr-like formula.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/where.html","id":"examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Select variables with a function — where","text":"Selection helpers can used functions like dplyr::select() tidyr::pivot_longer(). first attach tidyverse: () takes function returns variables function returns TRUE:","code":"library(tidyverse) # For better printing iris <- as_tibble(iris) is.factor(iris[[4]]) #> [1] FALSE is.factor(iris[[5]]) #> [1] TRUE iris %>% select(where(is.factor)) #> # A tibble: 150 x 1 #> Species #> #> 1 setosa #> 2 setosa #> 3 setosa #> 4 setosa #> # i 146 more rows is.numeric(iris[[4]]) #> [1] TRUE is.numeric(iris[[5]]) #> [1] FALSE iris %>% select(where(is.numeric)) #> # A tibble: 150 x 4 #> Sepal.Length Sepal.Width Petal.Length Petal.Width #> #> 1 5.1 3.5 1.4 0.2 #> 2 4.9 3 1.4 0.2 #> 3 4.7 3.2 1.3 0.2 #> 4 4.6 3.1 1.5 0.2 #> # i 146 more rows"},{"path":"https://tidyselect.r-lib.org/dev/reference/where.html","id":"the-formula-shorthand","dir":"Reference","previous_headings":"","what":"The formula shorthand","title":"Select variables with a function — where","text":"can use purrr-like formulas shortcut creating function spot. expressions equivalent: shorthand useful adding logic inline. select numeric variables whose mean greater 3.5:","code":"iris %>% select(where(is.numeric)) #> # A tibble: 150 x 4 #> Sepal.Length Sepal.Width Petal.Length Petal.Width #> #> 1 5.1 3.5 1.4 0.2 #> 2 4.9 3 1.4 0.2 #> 3 4.7 3.2 1.3 0.2 #> 4 4.6 3.1 1.5 0.2 #> # i 146 more rows iris %>% select(where(function(x) is.numeric(x))) #> # A tibble: 150 x 4 #> Sepal.Length Sepal.Width Petal.Length Petal.Width #> #> 1 5.1 3.5 1.4 0.2 #> 2 4.9 3 1.4 0.2 #> 3 4.7 3.2 1.3 0.2 #> 4 4.6 3.1 1.5 0.2 #> # i 146 more rows iris %>% select(where(~ is.numeric(.x))) #> # A tibble: 150 x 4 #> Sepal.Length Sepal.Width Petal.Length Petal.Width #> #> 1 5.1 3.5 1.4 0.2 #> 2 4.9 3 1.4 0.2 #> 3 4.7 3.2 1.3 0.2 #> 4 4.6 3.1 1.5 0.2 #> # i 146 more rows iris %>% select(where(~ is.numeric(.x) && mean(.x) > 3.5)) #> # A tibble: 150 x 2 #> Sepal.Length Petal.Length #> #> 1 5.1 1.4 #> 2 4.9 1.4 #> 3 4.7 1.3 #> 4 4.6 1.5 #> # i 146 more rows"},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"tidyselect-development-version","dir":"Changelog","previous_headings":"","what":"tidyselect (development version)","title":"tidyselect (development version)","text":"matches() now uses perl = TRUE default. makes consitent regular expressions stringr (#330). eval_select() now fails data duplicate names character vector provided input (#346). New args_tidy_select documentation topic. Use following tags document tidyselect arguments functions: eval_select() eval_relocate() gain new error_arg argument can specified throw better error message allow_empty = FALSE allow_rename = FALSE (@olivroy, #327). vars_pull() now also warns using .data (#335). Please use string-quotation programmatic usage, consistently tidyselect contexts. num_range() now recycles arguments using tidyverse rules (#355). addition, gains cross argument allows take cartesian product arguments instead. eval_select(allow_empty = FALSE) gains new argument yield better error message case empty selection (@olivroy, #327) eval_select() eval_relocate() gain new error_arg argument can specified throw better error message allow_empty = FALSE. eval_select() eval_relocate() throw classed error message allow_empty = FALSE (@olivroy, #347).","code":"#' @param ... <[`tidy-select`][tidyselect::args_tidy_select]> *doc* #' @param sel <[`tidy-select`][tidyselect::args_tidy_select]> *doc*"},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"tidyselect-121","dir":"Changelog","previous_headings":"","what":"tidyselect 1.2.1","title":"tidyselect 1.2.1","text":"CRAN release: 2024-03-11 Performance improvements (#337, #338, #339, #341) eval_select() --bounds errors now use verb “select” rather “subset” error message consistency dplyr::select() (#271). Fix CRAN checks.","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"tidyselect-120","dir":"Changelog","previous_headings":"","what":"tidyselect 1.2.0","title":"tidyselect 1.2.0","text":"CRAN release: 2022-10-10","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"new-features-1-2-0","dir":"Changelog","previous_headings":"","what":"New features","title":"tidyselect 1.2.0","text":"New tidyselect_data_proxy() tidyselect_data_has_predicates() allows tidyselect work custom input types (#242). New eval_relocate() moving selection. powers dplyr::relocate() (#232).","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"lifecycle-changes-1-2-0","dir":"Changelog","previous_headings":"","what":"Lifecycle changes","title":"tidyselect 1.2.0","text":"Using all_of() outside tidyselect context now deprecated (#269). future error consistent any_of(). Use .data tidyselect expressions now deprecated cleanly separate tidy-select data-masking. Replace .data$x \"x\" .data[[var]] all_of(var) (#169). Use bare predicates (wrapped ()) indirection (without using all_of()) formally deprecated (#317).","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"minor-improvements-and-bug-fixes-1-2-0","dir":"Changelog","previous_headings":"","what":"Minor improvements and bug fixes","title":"tidyselect 1.2.0","text":"Selection language: any_of() generates informative error supply many arguments (#241). all_of() (like any_of()) returns integer vector make easier combine functions (#270, #294). also fails can’t find variables even strict = FALSE. matches() recognises correctly uses stringr pattern objects (stringr::regex(), stringr::fixed(), etc) (#238). also now works named vectors (#250). num_range() gains suffix argument (#229). () now exported, like select helpers (#201), gives informative errors (#236). eval_select() include now preserves order variables ’re present selection (#224). eval_select() always returns named vector, even renaming permitted (#220). eval_select() eval_relocate() gain new allow_empty argument makes possible forbid empty selections allow_empty = FALSE (#252). eval_select(allow_rename = FALSE) longer fails empty selections (#221, @eutwt) predicate functions (#225). now properly fails partial renaming (#305). peek_var() error now generates hyperlink docs recent RStudio (#289). vars_pull() generates informative error messages (#234, #258, #318) gains error_call error_arg arguments. Errors produced tidyselect now informative. Evaluation errors now chained, child error call set error_call argument eval_select() eval_rename(). ’ve also improved backtraces base errors, done better propagating root error_call vctrs input checkers. tidyselect_verbosity longer used; deprecation messaging now controlled lifecycle_verbosity like packages (#317).","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"tidyselect-112","dir":"Changelog","previous_headings":"","what":"tidyselect 1.1.2","title":"tidyselect 1.1.2","text":"CRAN release: 2022-02-21 Fix CRAN checks. Better compatibility rlang 1.0.0 errors. come soon.","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"tidyselect-111","dir":"Changelog","previous_headings":"","what":"tidyselect 1.1.1","title":"tidyselect 1.1.1","text":"CRAN release: 2021-04-30 Fix CRAN checks. tidyselect re-licensed MIT (#217).","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"tidyselect-110","dir":"Changelog","previous_headings":"","what":"tidyselect 1.1.0","title":"tidyselect 1.1.0","text":"CRAN release: 2020-05-11 Predicate functions must now wrapped (). {r} iris %>% select((.factor)) made change avoid puzzling error messages variable unexpectedly missing data frame corresponding function environment: {r} # Attempts invoke `data()` function data.frame(x = 1) %>% select(data) Now tidyselect correctly complain missing variable rather trying invoke function. compatibility support predicate functions starting 1 version. eval_select() gains allow_rename argument. set FALSE, renaming variables c(foo = bar) syntax error. useful implement purely selective behaviour (#178). Fixed issue preventing repeated deprecation messages tidyselect_verbosity set \"verbose\" (#184). any_of() now preserves order input variables (#186). return value eval_select() now always named, even inputs constant (#173).","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"tidyselect-100","dir":"Changelog","previous_headings":"","what":"tidyselect 1.0.0","title":"tidyselect 1.0.0","text":"CRAN release: 2020-01-27 1.0.0 release tidyselect. features solidly defined implemented syntax, support predicate functions, new boolean operators, much .","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"documentation-1-0-0","dir":"Changelog","previous_headings":"","what":"Documentation","title":"tidyselect 1.0.0","text":"New Get started vignette client packages. Read vignette(\"tidyselect\") https://tidyselect.r-lib.org/articles/tidyselect.html. definition tidyselect language consolidated. technical description now available: https://tidyselect.r-lib.org/articles/syntax.html.","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"breaking-changes-1-0-0","dir":"Changelog","previous_headings":"","what":"Breaking changes","title":"tidyselect 1.0.0","text":"Selecting non-column variables bare names now triggers informative message suggesting use all_of() instead. Referring contextual objects bare name brittle might masked data frame column. Using all_of() safe (#76). tidyselect now uses vctrs validating inputs. changes may reveal programming errors previously silent. may also cause failures unit tests make faulty assumptions content error messages created tidyselect: --bounds errors thrown name doesn’t exist location large input. Logical vectors now fail properly. Selected variables now must unique. previously possible return duplicate selections circumstances. input names can longer contain NA values. Note recommend testthat::verify_output() monitoring error messages thrown packages don’t control. Unlike expect_error(), verify_output() cause CMD check failures error messages changed. See https://www.tidyverse.org/blog/2019/11/testthat-2-3-0/ information.","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"syntax-1-0-0","dir":"Changelog","previous_headings":"","what":"Syntax","title":"tidyselect 1.0.0","text":"boolean operators can now used create selections (#106). ! negates selection. | takes union two selections. & takes intersection two selections. patterns can currently achieved using -, c() intersect() respectively. boolean operators intuitive use. Many thanks Irene Steves (@isteves) suggesting UI. can now use predicate functions selection contexts: feature available functions use legacy interface tidyselect. need updated use new eval_select() function instead vars_select(). Unary - inside nested c() now consistently syntax set difference (#130). Improved support named elements. now possible assign name multiple elements, input data structure doesn’t require unique names (.e. anything data frame). selection engine rewritten support clearer separation data-expressions (calls :, -, c) env-expressions (anything else). means can now safely use expressions type: Even data frame data contains column also named data, subexpression ncol(data) still correctly evaluated. data:ncol(data) expression equivalent 2:3 data looked relevant context without ambiguity: example bit contrived, many realistic cases changes make easier write safe code: {r} select_from <- function(data, var) { data %>% dplyr::select({{ var }} : ncol(data)) } data %>% select_from(data) #> # tibble: 1 x 2 #> data bar #> #> 1 2 3","code":"iris %>% select(is.factor) iris %>% select(is.factor | is.numeric) data %>% select(1:ncol(data)) data %>% pivot_longer(1:ncol(data)) data <- tibble(foo = 1, data = 2, bar = 3) data %>% dplyr::select(data:ncol(data)) #> # A tibble: 1 x 2 #> data bar #> #> 1 2 3"},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"user-facing-improvements-1-0-0","dir":"Changelog","previous_headings":"","what":"User-facing improvements","title":"tidyselect 1.0.0","text":"new selection helpers all_of() any_of() strict variants one_of(). former always fails variables unknown, latter . all_of() safer use expect selected variables exist. any_of() useful cases, instance ensure variables selected : Note all_of() any_of() bit conservative function signature one_of(): accept dots. equivalent one_of(\"\", \"b\") all_of(c(\"\", \"b\")). Selection helpers like all_of() starts_with() now available selection contexts, even haven’t attached search path. visible consequence change now easier use selection functions without attaching host package: still recommended export helpers package users can easily look documentation ?. starts_with(), ends_with(), contains(), matches() now accept vector inputs (#50). instance now equivalent ways selecting variables start either \"\" \"b\": {r} starts_with(c(\"\", \"b\")) starts_with(\"\") | starts_with(\"b\") matches() new argument perl allow Perl-like regular expressions (@fmichonneau, #71) Better support selecting S3 vectors. instance, factors treated characters.","code":"vars <- c(\"Species\", \"Genus\") iris %>% dplyr::select(-any_of(vars)) # Before dplyr::select(mtcars, dplyr::starts_with(\"c\")) # After dplyr::select(mtcars, starts_with(\"c\"))"},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"api-1-0-0","dir":"Changelog","previous_headings":"","what":"API","title":"tidyselect 1.0.0","text":"New eval_select() eval_rename() functions client packages. replace vars_select() vars_rename(), now deprecated. functions: Take full data rather just names. makes possible use function predicates selection context. Return numeric vector locations rather vector names. makes possible use tidyselect inputs support duplicate names, like regular vectors.","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"other-features-and-fixes-1-0-0","dir":"Changelog","previous_headings":"","what":"Other features and fixes","title":"tidyselect 1.0.0","text":".strict argument vars_select() now works robustly consistently. Using arithmetic operators selection context now fails informatively (#84). now possible select columns data frames containing duplicate variables (#94). However, duplicates can’t part final selection. eval_rename() longer ignore names unquoted character vectors length 1 (#79). eval_rename() now fails variable renamed existing name (#70). eval_rename() better support existing duplicates (creating new duplicates error). eval_select(), eval_rename() vars_pull() now detect missing values uniformly (#72). vars_pull() now includes faulty expression error messages. performance issues eval_rename() many arguments fixed. make dplyr::rename_all() many columns much faster (@zkamvar, #92). tidyselect now much faster many columns, thanks performance fix rlang::env_bind() well internal fixes. vars_select() ignores vectors zeros (#82).","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"tidyselect-025","dir":"Changelog","previous_headings":"","what":"tidyselect 0.2.5","title":"tidyselect 0.2.5","text":"CRAN release: 2018-10-11 maintenance release compatibility rlang 0.3.0.","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"tidyselect-024","dir":"Changelog","previous_headings":"","what":"tidyselect 0.2.4","title":"tidyselect 0.2.4","text":"CRAN release: 2018-02-26 Fixed warning occurred vector column positions supplied vars_select() functions depending tidyr::gather() (#43 tidyverse/tidyr#374). Fixed compatibility issue rlang 0.2.0 (#51).","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"tidyselect-023","dir":"Changelog","previous_headings":"","what":"tidyselect 0.2.3","title":"tidyselect 0.2.3","text":"CRAN release: 2017-11-06 Internal fixes prevision using tidyselect within dplyr. vars_select() vars_rename() now correctly support unquoting character vectors names. vars_select() now ignores missing variables.","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"tidyselect-022","dir":"Changelog","previous_headings":"","what":"tidyselect 0.2.2","title":"tidyselect 0.2.2","text":"CRAN release: 2017-10-10 dplyr now correctly mentioned suggested package.","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"tidyselect-021","dir":"Changelog","previous_headings":"","what":"tidyselect 0.2.1","title":"tidyselect 0.2.1","text":"CRAN release: 2017-10-09 - now supports character vectors addition strings. makes easy unquote column names exclude set: {r} vars <- c(\"cyl\", \"\", \"disp\", \"drat\") vars_select(names(mtcars), - !!vars) last_col() now issues error variable vector empty. last_col() now returns column positions rather column names consistency helpers. also makes compatible functions like seq(). c() now supports character vectors way - seq(). (#37 @gergness)","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"tidyselect-020","dir":"Changelog","previous_headings":"","what":"tidyselect 0.2.0","title":"tidyselect 0.2.0","text":"CRAN release: 2017-08-30 main point release revert troublesome behaviour introduced tidyselect 0.1.0. also includes features.","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"evaluation-rules-0-2-0","dir":"Changelog","previous_headings":"","what":"Evaluation rules","title":"tidyselect 0.2.0","text":"special evaluation semantics selection changed back old behaviour new rules causing much trouble confusion. now data expressions (symbols calls : c()) can refer registered variables objects context. However semantics context expressions (calls : c()) remain . expressions evaluated context refer registered variables. ’re writing functions refer contextual objects, still good idea avoid data expressions. Since registered variables change function user input never know local objects might shadowed variable. Consider: select second element letters 14th? Since variables precedence data expression, select 14 first letters. can made robust turning data expression context expression: can also use quasiquotation since unquoted arguments guaranteed evaluated without user data scope. equivalent special rules context expressions, may clearer reader accustomed tidy eval: {r} vars_select(letters, seq(1, !! n)) Finally, may want explicit opposite direction. expect variable found data context, can use .data pronoun: {r} vars_select(names(mtcars), .data$cyl : .data$drat)","code":"n <- 2 vars_select(letters, 1:n) vars_select(letters, seq(1, n))"},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"new-features-0-2-0","dir":"Changelog","previous_headings":"","what":"New features","title":"tidyselect 0.2.0","text":"new select helper last_col() helpful select custom range: vars_select(vars, 3:last_col()). : - now handle strings well. makes easy unquote column name: (!!name) : last_col() - !!name. vars_select() gains .strict argument similar rename_vars(). set FALSE, errors unknown variables ignored. vars_select() now treats NULL empty inputs. follows trend tidyverse tools. vars_rename() now handles variable positions (integers round doubles) just like vars_select() (#20). vars_rename() now implemented tidy eval framework. Like vars_select(), expressions evaluated without user data scope. addition variable context now established can write rename helpers. return single round number string (variable position variable name). has_vars() predicate tests whether variable context set (#21). selection helpers now exported list vars_select_helpers. intended APIs embed helpers evaluation environment.","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"fixes-0-2-0","dir":"Changelog","previous_headings":"","what":"Fixes","title":"tidyselect 0.2.0","text":"one_of() argument vars renamed .vars avoid spurious matching.","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"tidyselect-011","dir":"Changelog","previous_headings":"","what":"tidyselect 0.1.1","title":"tidyselect 0.1.1","text":"CRAN release: 2017-07-24 tidyselect new home legacy functions dplyr::select_vars(), dplyr::rename_vars() dplyr::select_var().","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"api-changes-0-1-1","dir":"Changelog","previous_headings":"","what":"API changes","title":"tidyselect 0.1.1","text":"took opportunity make changes API: select_vars() rename_vars() now vars_select() vars_rename(). follows tidyverse convention prefix corresponds input type suffixes indicate output type. Similarly, select_var() now vars_pull(). arguments now prefixed dots limit argument matching issues. dots help, still good idea splice list captured quosures make sure dotted arguments never matched vars_select()’s named arguments: Error messages can now customised. consistency dplyr, error messages refer “columns” default. assumes variables selected come data frame. appropriate DSL, can now add attribute vars_type .vars vector specify alternative names. must character vector length 2 whose first component singular form second plural. example, c(\"variable\", \"variables\").","code":"vars_select(vars, !!! quos(...))"},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"establishing-a-variable-context-0-1-1","dir":"Changelog","previous_headings":"","what":"Establishing a variable context","title":"tidyselect 0.1.1","text":"tidyselect provides ways establishing variable context: scoped_vars() sets variable context along exit hook automatically restores previous variables. preferred way changing variable context. with_vars() takes variables expression evaluates latter context former. poke_vars() establishes new variable context. returns previous context invisibly responsibility restore done. expert use . current_vars() renamed peek_vars(). naming reference peek poke legacy languages.","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"new-evaluation-semantics-0-1-1","dir":"Changelog","previous_headings":"","what":"New evaluation semantics","title":"tidyselect 0.1.1","text":"evaluation semantics selecting verbs changed. Symbols now evaluated data-context isolated calling environment. means can longer refer local variables unless explicitly unquoting variables !!, mostly expert use. Note since dplyr 0.7, helper calls (like starts_with()) obey opposite behaviour evaluated calling context isolated data context. sum , symbols can refer data frame objects, helpers can refer contextual objects. differs usual R evaluation semantics data calling environment scope (former prevailing latter).","code":""}] +[{"path":[]},{"path":"https://tidyselect.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"our-pledge","dir":"","previous_headings":"","what":"Our Pledge","title":"Contributor Covenant Code of Conduct","text":"members, contributors, leaders pledge make participation community harassment-free experience everyone, regardless age, body size, visible invisible disability, ethnicity, sex characteristics, gender identity expression, level experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, sexual identity orientation. pledge act interact ways contribute open, welcoming, diverse, inclusive, healthy community.","code":""},{"path":"https://tidyselect.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"our-standards","dir":"","previous_headings":"","what":"Our Standards","title":"Contributor Covenant Code of Conduct","text":"Examples behavior contributes positive environment community include: Demonstrating empathy kindness toward people respectful differing opinions, viewpoints, experiences Giving gracefully accepting constructive feedback Accepting responsibility apologizing affected mistakes, learning experience Focusing best just us individuals, overall community Examples unacceptable behavior include: use sexualized language imagery, sexual attention advances kind Trolling, insulting derogatory comments, personal political attacks Public private harassment Publishing others’ private information, physical email address, without explicit permission conduct reasonably considered inappropriate professional setting","code":""},{"path":"https://tidyselect.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"enforcement-responsibilities","dir":"","previous_headings":"","what":"Enforcement Responsibilities","title":"Contributor Covenant Code of Conduct","text":"Community leaders responsible clarifying enforcing standards acceptable behavior take appropriate fair corrective action response behavior deem inappropriate, threatening, offensive, harmful. Community leaders right responsibility remove, edit, reject comments, commits, code, wiki edits, issues, contributions aligned Code Conduct, communicate reasons moderation decisions appropriate.","code":""},{"path":"https://tidyselect.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"scope","dir":"","previous_headings":"","what":"Scope","title":"Contributor Covenant Code of Conduct","text":"Code Conduct applies within community spaces, also applies individual officially representing community public spaces. Examples representing community include using official e-mail address, posting via official social media account, acting appointed representative online offline event.","code":""},{"path":"https://tidyselect.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"enforcement","dir":"","previous_headings":"","what":"Enforcement","title":"Contributor Covenant Code of Conduct","text":"Instances abusive, harassing, otherwise unacceptable behavior may reported community leaders responsible enforcement codeofconduct@posit.co. complaints reviewed investigated promptly fairly. community leaders obligated respect privacy security reporter incident.","code":""},{"path":"https://tidyselect.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"enforcement-guidelines","dir":"","previous_headings":"","what":"Enforcement Guidelines","title":"Contributor Covenant Code of Conduct","text":"Community leaders follow Community Impact Guidelines determining consequences action deem violation Code Conduct:","code":""},{"path":"https://tidyselect.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_1-correction","dir":"","previous_headings":"Enforcement Guidelines","what":"1. Correction","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Use inappropriate language behavior deemed unprofessional unwelcome community. Consequence: private, written warning community leaders, providing clarity around nature violation explanation behavior inappropriate. public apology may requested.","code":""},{"path":"https://tidyselect.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_2-warning","dir":"","previous_headings":"Enforcement Guidelines","what":"2. Warning","title":"Contributor Covenant Code of Conduct","text":"Community Impact: violation single incident series actions. Consequence: warning consequences continued behavior. interaction people involved, including unsolicited interaction enforcing Code Conduct, specified period time. includes avoiding interactions community spaces well external channels like social media. Violating terms may lead temporary permanent ban.","code":""},{"path":"https://tidyselect.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_3-temporary-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"3. Temporary Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: serious violation community standards, including sustained inappropriate behavior. Consequence: temporary ban sort interaction public communication community specified period time. public private interaction people involved, including unsolicited interaction enforcing Code Conduct, allowed period. Violating terms may lead permanent ban.","code":""},{"path":"https://tidyselect.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"id_4-permanent-ban","dir":"","previous_headings":"Enforcement Guidelines","what":"4. Permanent Ban","title":"Contributor Covenant Code of Conduct","text":"Community Impact: Demonstrating pattern violation community standards, including sustained inappropriate behavior, harassment individual, aggression toward disparagement classes individuals. Consequence: permanent ban sort public interaction within community.","code":""},{"path":"https://tidyselect.r-lib.org/dev/CODE_OF_CONDUCT.html","id":"attribution","dir":"","previous_headings":"","what":"Attribution","title":"Contributor Covenant Code of Conduct","text":"Code Conduct adapted Contributor Covenant, version 2.1, available https://www.contributor-covenant.org/version/2/1/code_of_conduct.html. Community Impact Guidelines inspired [Mozilla’s code conduct enforcement ladder][https://github.com/mozilla/inclusion]. answers common questions code conduct, see FAQ https://www.contributor-covenant.org/faq. Translations available https://www.contributor-covenant.org/translations.","code":""},{"path":"https://tidyselect.r-lib.org/dev/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"MIT License","title":"MIT License","text":"Copyright (c) 2024 tidyselect authors Permission hereby granted, free charge, person obtaining copy software associated documentation files (“Software”), deal Software without restriction, including without limitation rights use, copy, modify, merge, publish, distribute, sublicense, /sell copies Software, permit persons Software furnished , subject following conditions: copyright notice permission notice shall included copies substantial portions Software. SOFTWARE PROVIDED “”, WITHOUT WARRANTY KIND, EXPRESS IMPLIED, INCLUDING LIMITED WARRANTIES MERCHANTABILITY, FITNESS PARTICULAR PURPOSE NONINFRINGEMENT. EVENT SHALL AUTHORS COPYRIGHT HOLDERS LIABLE CLAIM, DAMAGES LIABILITY, WHETHER ACTION CONTRACT, TORT OTHERWISE, ARISING , CONNECTION SOFTWARE USE DEALINGS SOFTWARE.","code":""},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"sets-of-variables","dir":"Articles","previous_headings":"","what":"Sets of variables","title":"Technical description of tidyselect","text":"tidyselect syntax sets variables, internally represented integer vectors locations. example, c(1L, 2L) represents set first second variables, c(1L, 2L, 1L). vector locations contains duplicates, normally treated element, since represent sets. exception occurs named elements whose names differ. names don’t match, treated different elements order allow renaming variable multiple names (see section Renaming variables). Today, syntax tidyselect generally designed around Boolean algebra, .e. recommend writing starts_with(\"\") & !ends_with(\"z\"). Earlier versions tidyselect flavour set operations, ’d write starts_with(\"\") - ends_with(\"b\"). set operations still supported, tidyselect represents variables internally, longer recommend Boolean algebra easy people understand.","code":""},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"bare-names","dir":"Articles","previous_headings":"Sets of variables","what":"Bare names","title":"Technical description of tidyselect","text":"Within data-expressions (see Evaluation section), bare names represent locations, .e. set size 1. following expressions equivalent:","code":"mtcars %>% select_loc(mpg:hp, !cyl, vs) #> mpg cyl disp hp drat wt qsec vs am gear carb #> 1 2 3 4 5 6 7 8 9 10 11 mtcars %>% select_loc(1:4, !2, 8) #> mpg cyl disp hp drat wt qsec vs am gear carb #> 1 2 3 4 5 6 7 8 9 10 11"},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"the-operator","dir":"Articles","previous_headings":"Sets of variables","what":"The : operator","title":"Technical description of tidyselect","text":": can used select consecutive variables two locations. returns corresponding sequence locations. bare names represent locations, easy select range variables:","code":"mtcars %>% select_loc(2:4) #> cyl disp hp #> 2 3 4 mtcars %>% select_loc(cyl:hp) #> cyl disp hp #> 2 3 4"},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"boolean-operators","dir":"Articles","previous_headings":"Sets of variables","what":"Boolean operators","title":"Technical description of tidyselect","text":"| operator takes union two sets: & operator takes intersection two sets: ! operator takes complement set: Taking intersection complement produces set difference:","code":"iris %>% select_loc(starts_with(\"Sepal\") | ends_with(\"Width\")) #> Sepal.Length Sepal.Width Petal.Width #> 1 2 4 iris %>% select_loc(starts_with(\"Sepal\") & ends_with(\"Width\")) #> Sepal.Width #> 2 iris %>% select_loc(!ends_with(\"Width\")) #> Sepal.Length Petal.Length Species #> 1 3 5 iris %>% select_loc(starts_with(\"Sepal\") & !ends_with(\"Width\")) #> Sepal.Length #> 1"},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"dots-and-c","dir":"Articles","previous_headings":"Sets of variables","what":"Dots and c()","title":"Technical description of tidyselect","text":"tidyselect functions can take dots, like dplyr::select(), named argument, like tidyr::pivot_longer(). latter case, dots syntax accessible via c(). fact ... syntax implemented c(...) thus completely equivalent. c(x, y, z) equivalent x | y | z:","code":"mtcars %>% select_loc(mpg, disp:hp) #> mpg disp hp #> 1 3 4 mtcars %>% select_loc(c(mpg, disp:hp)) #> mpg disp hp #> 1 3 4 iris %>% select_loc(starts_with(\"Sepal\"), ends_with(\"Width\"), Species) #> Sepal.Length Sepal.Width Petal.Width Species #> 1 2 4 5 iris %>% select_loc(starts_with(\"Sepal\") | ends_with(\"Width\") | Species) #> Sepal.Length Sepal.Width Petal.Width Species #> 1 2 4 5"},{"path":[]},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"name-combination-and-propagation","dir":"Articles","previous_headings":"Sets of variables > Renaming variables","what":"Name combination and propagation","title":"Technical description of tidyselect","text":"named inputs provided ... c(), selection renamed. inputs already named, outer inner names combined ... separator: Otherwise outer names propagated selected elements according following rules: data frames, numeric suffix appended columns must uniquely named. normal vectors, name simply assigned selected inputs. Combination propagation can composed using nested c():","code":"mtcars %>% select_loc(foo = c(bar = mpg, baz = cyl)) #> foo...bar foo...baz #> 1 2 mtcars %>% select_loc(foo = c(mpg, cyl)) #> foo1 foo2 #> 1 2 as.list(mtcars) %>% select_loc(foo = c(mpg, cyl)) #> foo foo #> 1 2 mtcars %>% select_loc(foo = c(bar = c(mpg, cyl))) #> foo...bar1 foo...bar2 #> 1 2"},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"set-combination-with-named-variables","dir":"Articles","previous_headings":"Sets of variables > Renaming variables","what":"Set combination with named variables","title":"Technical description of tidyselect","text":"Named elements special rules determine identities set. Unnamed elements match names: | c(foo = ) equivalent c(foo = ). & c(foo = ) equivalent c(foo = ). Named elements different names distinct: c(foo = ) & c(bar = ) equivalent c(). c(foo = ) | c(bar = ) equivalent c(foo = , bar = ). unnamed elements match named ones, possible select multiple elements rename one :","code":"iris %>% select_loc(!Species, foo = Sepal.Width) #> Sepal.Length foo Petal.Length Petal.Width #> 1 2 3 4"},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"predicate-functions","dir":"Articles","previous_headings":"Sets of variables","what":"Predicate functions","title":"Technical description of tidyselect","text":"Predicate function objects can supplied input env-expression, typically selection helper (). applied elements data, return TRUE FALSE indicate inclusion. Predicates env-expressions effectively expanded set variables represent:","code":"iris %>% select_loc(where(is.numeric)) #> Sepal.Length Sepal.Width Petal.Length Petal.Width #> 1 2 3 4 iris %>% select_loc(where(is.factor)) #> Species #> 5 iris %>% select_loc(where(is.numeric) | where(is.factor)) #> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> 1 2 3 4 5 iris %>% select_loc(where(is.numeric) & where(is.factor)) #> named integer(0)"},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"selection-helpers","dir":"Articles","previous_headings":"","what":"Selection helpers","title":"Technical description of tidyselect","text":"call selection helpers function inspects currently active variables peek_vars() returns selection. peek_vars() returns character vector names. returned selection can output conforming types described Data types section. Examples selection helpers all_of(), contains(), last_col(). selection helpers evaluated env-expressions (see Evaluation section).","code":""},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"supported-data-types","dir":"Articles","previous_headings":"","what":"Supported data types","title":"Technical description of tidyselect","text":"following data types can returned selection helpers forced via !! force() (latter works tidyselect treated env-expression, see Evaluation section): Vectors locations: Vectors names. matched transformed locations. Predicate functions. applied elements determine inclusion.","code":"iris %>% select_loc(force(c(1, 3))) #> Sepal.Length Petal.Length #> 1 3 iris %>% select_loc(force(c(\"Sepal.Length\", \"Petal.Length\"))) #> Sepal.Length Petal.Length #> 1 3 iris %>% select_loc(force(is.numeric)) #> Sepal.Length Sepal.Width Petal.Length Petal.Width #> 1 2 3 4"},{"path":[]},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"data-expressions-and-env-expressions","dir":"Articles","previous_headings":"Evaluation","what":"Data-expressions and env-expressions","title":"Technical description of tidyselect","text":"tidyselect typical tidy evaluation UI. main difference data masking. typical tidy eval function, expressions evaluated data-vars first scope, followed env-vars: possible bypass data frame variables forcing symbols looked environment !! .env: tidyselect, hierarchical data masking. Instead, expressions evaluated either context data frame user environment, without overlap. scope lookup depends kind expression: data-expressions evaluated data frame . includes bare symbols, boolean operators, -, :, c(). can’t refer environment-variables data-expression: env-expressions evaluated environment. includes calls mentioned , well symbols part calls. can’t refer data-variables data-expression: scoping unambiguous, can safely refer env-vars env-expression, without worry potential naming clashes data-vars: variable names character vector, safe refer env-var containing names all_of() env-expression: Note currently, env-vars still allowed data-expressions, compatibility. However process deprecated see note recommending use all_of() instead. note become deprecation warning future, error.","code":"mask <- function(data, expr) { rlang::eval_tidy(rlang::enquo(expr), data) } foo <- 10 cyl <- 200 # `cyl` represents the data frame column here: mtcars %>% mask(cyl * foo) #> [1] 60 60 40 60 80 60 80 40 40 60 60 80 80 80 80 80 80 40 40 40 40 80 80 #> [24] 80 80 40 40 40 80 60 80 40 mtcars %>% mask(!!cyl * foo) #> [1] 2000 mtcars %>% mask(.env$cyl * foo) #> [1] 2000 cyl_pos <- 2 mtcars %>% select_loc(mpg | cyl_pos) #> Error in `select_loc()`: #> ! Can't select columns that don't exist. #> ✖ Column `cyl_pos` doesn't exist. mtcars %>% select_loc(all_of(mpg)) #> Error in `select_loc()`: #> ℹ In argument: `all_of(mpg)`. #> Caused by error: #> ! object 'mpg' not found x <- data.frame(x = 1:3, y = 4:6, z = 7:9) # `ncol(x)` is an env-expression, so `x` represents the data frame in # the environment rather than the column in the data frame x %>% select_loc(2:ncol(x)) #> y z #> 2 3 y <- c(\"y\", \"z\") x %>% select_loc(all_of(y)) #> y z #> 2 3 mtcars %>% select_loc(cyl_pos) #> Warning: Using an external vector in selections was deprecated in tidyselect #> 1.1.0. #> ℹ Please use `all_of()` or `any_of()` instead. #> ℹ See . #> This warning is displayed once every 8 hours. #> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was #> generated. #> cyl #> 2"},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"arithmetic-operators","dir":"Articles","previous_headings":"Evaluation","what":"Arithmetic operators","title":"Technical description of tidyselect","text":"Within data-expressions (see Evaluation section), +, * / overridden cause error. prevent confusion stemming normal data masking usage variables can transformed fly:","code":"mtcars %>% select_loc(cyl^2) #> Error in `select_loc()`: #> ! Can't use arithmetic operator `^` in selection context. mtcars %>% select_loc(mpg * wt) #> Error in `select_loc()`: #> ! Can't use arithmetic operator `*` in selection context."},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"selecting-versus-renaming","dir":"Articles","previous_headings":"","what":"Selecting versus renaming","title":"Technical description of tidyselect","text":"select rename variants take types inputs type return value. important differences.","code":""},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"all-renaming-inputs-must-be-named","dir":"Articles","previous_headings":"Selecting versus renaming","what":"All renaming inputs must be named","title":"Technical description of tidyselect","text":"Unlike eval_select() can select without renaming, eval_rename() expects fully named selection. one several names missing, error thrown.","code":"mtcars %>% select_loc(mpg) #> mpg #> 1 mtcars %>% rename_loc(mpg) #> Error in `rename_loc()`: #> ! All renaming inputs must be named."},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"renaming-to-an-existing-variable-name","dir":"Articles","previous_headings":"Selecting versus renaming","what":"Renaming to an existing variable name","title":"Technical description of tidyselect","text":"input data data frame, tidyselect generally throws error duplicate column names selected, order respect invariant unique column names. selection can rename variable existing name latter part selection: possible renaming. However, name conflict can solved renaming existing variable another name:","code":"# Lists can have duplicates as.list(mtcars) %>% select_loc(foo = mpg, foo = cyl) #> foo foo #> 1 2 # Data frames cannot mtcars %>% select_loc(foo = mpg, foo = cyl) #> Error in `select_loc()`: #> ! Names must be unique. #> ✖ These names are duplicated: #> * \"foo\" at locations 1 and 2. mtcars %>% select_loc(cyl, cyl = mpg) #> Error in `select_loc()`: #> ! Names must be unique. #> ✖ These names are duplicated: #> * \"cyl\" at locations 1 and 2. mtcars %>% select_loc(disp, cyl = mpg) #> disp cyl #> 3 1 mtcars %>% rename_loc(cyl, cyl = mpg) #> Error in `rename_loc()`: #> ! All renaming inputs must be named. mtcars %>% rename_loc(disp, cyl = mpg) #> Error in `rename_loc()`: #> ! All renaming inputs must be named. mtcars %>% select_loc(foo = cyl, cyl = mpg) #> foo cyl #> 2 1 mtcars %>% rename_loc(foo = cyl, cyl = mpg) #> foo cyl #> 2 1"},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"duplicate-columns-in-data-frames","dir":"Articles","previous_headings":"","what":"Duplicate columns in data frames","title":"Technical description of tidyselect","text":"Normally data frame shouldn’t duplicate names. However, real world messy duplicates happen wild. tidyselect tries permissive can duplicates users can restore unique names select() rename(). First let’s create data frame duplicate names: duplicates part selection, simply ignored: duplicates selected, error: duplicate names can repaired renaming chosen locations:","code":"dups <- vctrs::new_data_frame(list(x = 1, y = 2, x = 3)) dups %>% select_loc(y) #> y #> 2 dups %>% select_loc(x) #> Error in `select_loc()`: #> ! Names must be unique. #> ✖ These names are duplicated: #> * \"x\" at locations 1 and 2. dups %>% select_loc(x, foo = 3) #> x foo #> 1 3 dups %>% rename_loc(foo = 3) #> foo #> 3"},{"path":"https://tidyselect.r-lib.org/dev/articles/syntax.html","id":"acknowledgements","dir":"Articles","previous_headings":"","what":"Acknowledgements","title":"Technical description of tidyselect","text":"tidyselect syntax inspired base::subset() function written Peter Dalgaard. select parameter subset.data.frame() evaluated data mask column names bound locations data frame. allows : create sequences variable locations. locations can combined c(). selection interface set tone development tidyselect syntax.","code":"mtcars %>% subset(select = c(cyl, hp:wt)) #> # A tibble: 32 × 4 #> cyl hp drat wt #> #> 1 6 110 3.9 2.62 #> 2 6 110 3.9 2.88 #> 3 4 93 3.85 2.32 #> 4 6 110 3.08 3.22 #> # ℹ 28 more rows"},{"path":[]},{"path":"https://tidyselect.r-lib.org/dev/articles/tidyselect.html","id":"selections-as-dots-or-as-named-arguments","dir":"Articles","previous_headings":"Before we start","what":"Selections as dots or as named arguments","title":"Implementing tidyselect interfaces","text":"two major ways designing function takes selections. Passing dots dplyr::select(). Interpolating named arguments tidyr::pivot_longer(). case, multiple inputs can provided inside c() using boolean operators: general recommendation take dots main purpose function create new data structure based selection. selection accessory main purpose function, take named argument. doubt, recommend using named arguments easier change named argument dots way around. advice , see Making data ... section tidyverse design book.","code":"mtcars %>% dplyr::select(mpg, cyl) mtcars %>% pivot_longer(c(mpg, cyl)) mtcars %>% pivot_longer(mpg | cyl)"},{"path":"https://tidyselect.r-lib.org/dev/articles/tidyselect.html","id":"do-you-need-tidyselect","dir":"Articles","previous_headings":"Before we start","what":"Do you need tidyselect?","title":"Implementing tidyselect interfaces","text":"tools described vignette rather low level. Depending use case, may easier wrap dplyr::select(). ’ll get data frame containing columns selected user, can handle various ways. following examples illustrate write function takes selection data returns corresponding data frame capitalised names: main advantage lower level tidyselect tools offer bit information flexibility. Instead returning selected data, return locations selected elements inside input data. don’t need selected locations can afford dependency, may consider wrapping dplyr instead.","code":"# Passing dots toupper_dots <- function(data, ...) { sel <- dplyr::select(data, ...) rlang::set_names(sel, toupper) } # Interpolating a named argument with {{ }} toupper_arg <- function(data, arg) { sel <- dplyr::select(data, {{ arg }}) rlang::set_names(sel, toupper) } mtcars %>% toupper_dots(mpg:disp, vs) #> # A tibble: 32 x 4 #> MPG CYL DISP VS #> #> 1 21 6 160 0 #> 2 21 6 160 0 #> 3 22.8 4 108 1 #> 4 21.4 6 258 1 #> # … with 28 more rows mtcars %>% toupper_arg(c(mpg:disp, vs)) #> # A tibble: 32 x 4 #> MPG CYL DISP VS #> #> 1 21 6 160 0 #> 2 21 6 160 0 #> 3 22.8 4 108 1 #> 4 21.4 6 258 1 #> # … with 28 more rows"},{"path":"https://tidyselect.r-lib.org/dev/articles/tidyselect.html","id":"the-selection-evaluators","dir":"Articles","previous_headings":"","what":"The selection evaluators","title":"Implementing tidyselect interfaces","text":"tidyselect implemented non-standard evaluation (NSE). unique feature R language refers ability functions defuse (.e. delay execution) arguments, resume evaluation later on1. Crucially, evaluation can resumed different context according different rules, often domain-specific languages created R.","code":""},{"path":"https://tidyselect.r-lib.org/dev/articles/tidyselect.html","id":"defusing-and-resuming-evaluation-of-r-code","dir":"Articles","previous_headings":"The selection evaluators","what":"Defusing and resuming evaluation of R code","title":"Implementing tidyselect interfaces","text":"function argument defused, R halts evaluation code returns defused expression instead. expression contains code describes compute intended value. Defuse R code expr(): Defuse user’s R code enquo(): resume evaluation defused R code, use eval_tidy(): can resume evaluation data context passing data frame data argument: Resuming evaluation data context known data masking. data-vars inside data frame combined env-vars environment, making possible users refer data variables:","code":"own <- rlang::expr(1 + 2) own #> 1 + 2 fn <- function(arg) { expr <- rlang::enquo(arg) expr } user <- fn(1 + 2) user #> #> expr: ^1 + 2 #> env: global rlang::eval_tidy(own) #> [1] 3 rlang::eval_tidy(user) #> [1] 3 with_data <- function(data, x) { expr <- rlang::enquo(x) rlang::eval_tidy(expr, data = data) } NULL %>% with_data(mean(cyl) * 10) #> Error: object 'cyl' not found mtcars %>% with_data(mean(cyl) * 10) #> [1] 61.875"},{"path":"https://tidyselect.r-lib.org/dev/articles/tidyselect.html","id":"resuming-defused-r-code-with-tidyselect-rules","dir":"Articles","previous_headings":"The selection evaluators","what":"Resuming defused R code with tidyselect rules","title":"Implementing tidyselect interfaces","text":"Taking tidyselect selections functions follows principles. First defuse expression, resume evaluation. Instead eval_tidy(), need special interpreters eval_select() eval_rename(). Like eval_tidy(), take defused expression data. return vector locations selected elements: user renamed selected elements, names vector locations reflect new names. eval_select() likely variant ’ll need implement tidyselect functions.","code":"eval_select(rlang::expr(mpg), mtcars) #> mpg #> 1 eval_select(rlang::expr(c(mpg:disp, vs)), mtcars) #> mpg cyl disp vs #> 1 2 3 8 eval_select(rlang::expr(c(foo = mpg, bar = disp)), mtcars) #> foo bar #> 1 3 eval_rename(rlang::expr(c(foo = mpg, bar = disp)), mtcars) #> foo bar #> 1 3"},{"path":"https://tidyselect.r-lib.org/dev/articles/tidyselect.html","id":"simple-selections-with-dots","dir":"Articles","previous_headings":"The selection evaluators > Resuming defused R code with tidyselect rules","what":"Simple selections with dots","title":"Implementing tidyselect interfaces","text":"selecting function takes dots: Pass dots c() inside defused expression. Resume evaluation defused c() expression eval_select(). Use vector locations returned eval_select() subset rename input data. reimplement dplyr::select() 3 lines representing steps :","code":"select <- function(.data, ...) { expr <- rlang::expr(c(...)) pos <- eval_select(expr, data = .data) rlang::set_names(.data[pos], names(pos)) } mtcars %>% select(mpg, cyl) #> # A tibble: 32 × 2 #> mpg cyl #> #> 1 21 6 #> 2 21 6 #> 3 22.8 4 #> 4 21.4 6 #> # ℹ 28 more rows"},{"path":"https://tidyselect.r-lib.org/dev/articles/tidyselect.html","id":"simple-selections-with-named-arguments","dir":"Articles","previous_headings":"The selection evaluators > Resuming defused R code with tidyselect rules","what":"Simple selections with named arguments","title":"Implementing tidyselect interfaces","text":"selecting function takes named arguments, defusing step bit different. need use enquo() defuse function argument .","code":"select <- function(.data, cols) { expr <- rlang::enquo(cols) pos <- eval_select(expr, data = .data) rlang::set_names(.data[pos], names(pos)) } mtcars %>% select(c(mpg, cyl)) #> # A tibble: 32 × 2 #> mpg cyl #> #> 1 21 6 #> 2 21 6 #> 3 22.8 4 #> 4 21.4 6 #> # ℹ 28 more rows"},{"path":"https://tidyselect.r-lib.org/dev/articles/tidyselect.html","id":"renaming-selections","dir":"Articles","previous_headings":"The selection evaluators > Resuming defused R code with tidyselect rules","what":"Renaming selections","title":"Implementing tidyselect interfaces","text":"eval_rename() variant rarely needed mentioned completeness. First note eval_select() eval_rename() allow renaming variables: eval_rename() similar eval_select() constraints meant renaming variables place. particular throws error selected inputs unnamed. practice, eval_rename() accepts c() expression expr argument, inputs inside outermost c() must named: constraint, doesn’t make much sense take named argument, time ’ll want pass dots defused c() expression. way user can easily pass names selections: example use vector locations returned eval_rename(), implement dplyr::rename():","code":"eval_select(rlang::expr(c(foo = mpg)), mtcars) #> foo #> 1 eval_rename(rlang::expr(c(foo = mpg)), mtcars) #> foo #> 1 eval_rename(rlang::expr(mpg), mtcars) #> Error: #> ! All renaming inputs must be named. eval_rename(rlang::expr(c(mpg)), mtcars) #> Error: #> ! All renaming inputs must be named. eval_rename(rlang::expr(c(foo = mpg)), mtcars) #> foo #> 1 wrapper <- function(data, ...) { eval_rename(rlang::expr(c(...)), data) } mtcars %>% wrapper(foo = mpg, bar = hp:wt) #> foo bar1 bar2 bar3 #> 1 4 5 6 rename <- function(.data, ...) { pos <- eval_rename(rlang::expr(c(...)), .data) names(.data)[pos] <- names(pos) .data } mtcars %>% rename(foo = mpg, bar = hp:wt) #> # A tibble: 32 × 11 #> foo cyl disp bar1 bar2 bar3 qsec vs am gear carb #> #> 1 21 6 160 110 3.9 2.62 16.5 0 1 4 4 #> 2 21 6 160 110 3.9 2.88 17.0 0 1 4 4 #> 3 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1 #> 4 21.4 6 258 110 3.08 3.22 19.4 1 0 3 1 #> # ℹ 28 more rows"},{"path":"https://tidyselect.r-lib.org/dev/articles/tidyselect.html","id":"creating-selection-helpers","dir":"Articles","previous_headings":"","what":"Creating selection helpers","title":"Implementing tidyselect interfaces","text":"Tools like starts_with() contains() called selection helpers. tools inspect variable names currently available selection peek_vars(). variable names registered automatically eval_select() duration evaluation: properties temporarily available calling function like peek_vars() called descriptors. Descriptors useful easy compose. instance, user combine starts_with() ends_with() without worry passing variables environment can found: create new selection helper: Inspect variables peek_vars(). convention done argument user can override. Return one supported data types: vector names locations (latter recommended, see section handling duplicate variables), predicate function. fn argument makes error message informative helper used wrong context: variables inspected default argument, easy override. mostly useful unit tests:","code":"x <- rlang::expr(print(peek_vars())) invisible(eval_select(x, data = mtcars)) #> [1] \"mpg\" \"cyl\" \"disp\" \"hp\" \"drat\" \"wt\" \"qsec\" \"vs\" \"am\" \"gear\" #> [11] \"carb\" my_selector <- function(prefix, suffix) { intersect( starts_with(prefix), ends_with(suffix) ) } iris %>% select(my_selector(\"Sepal\", \"Length\")) #> # A tibble: 150 × 1 #> Sepal.Length #> #> 1 5.1 #> 2 4.9 #> 3 4.7 #> 4 4.6 #> # ℹ 146 more rows if_width <- function(n, vars = peek_vars(fn = \"if_width\")) { vars[nchar(vars) == n] } mtcars %>% select(if_width(2)) #> # A tibble: 32 × 4 #> hp wt vs am #> #> 1 110 2.62 0 1 #> 2 110 2.88 0 1 #> 3 93 2.32 1 1 #> 4 110 3.22 1 0 #> # ℹ 28 more rows mtcars[if_width(2)] #> Error: #> ! `if_width()` must be used within a *selecting* function. #> ℹ See #> for details. if_width(2, vars = names(mtcars)) #> [1] \"hp\" \"wt\" \"vs\" \"am\""},{"path":"https://tidyselect.r-lib.org/dev/articles/tidyselect.html","id":"handling-duplicate-variables","dir":"Articles","previous_headings":"Creating selection helpers","what":"Handling duplicate variables","title":"Implementing tidyselect interfaces","text":"However current implementation if_width() design flaw. doesn’t work properly input duplicate names: Supporting duplicates recommended data frames wild don’t always unique names. Also, tidyselect can used vectors don’t require unique names, might extended allow recoding character vectors future. cases, handling duplicates part normal usage selection helpers. support duplicates recommended return vectors locations selection helpers rather vector names. Fixing if_width() easy: input data frame, user now informed selection contain duplicates: duplicates selected input data frame, expected:","code":"dups <- vctrs::new_data_frame(list(foo = 1, quux = 2, foo = 3)) dups %>% select(if_width(3)) #> foo #> 1 1 if_width <- function(n, vars = peek_vars(fn = \"if_width\")) { which(nchar(vars) == n) } dups %>% select(if_width(3)) #> Error in `select()`: #> ! Names must be unique. #> ✖ These names are duplicated: #> * \"foo\" at locations 1 and 2. as.list(dups) %>% select(if_width(3)) #> $foo #> [1] 1 #> #> $foo #> [1] 3"},{"path":"https://tidyselect.r-lib.org/dev/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Lionel Henry. Author, maintainer. Hadley Wickham. Author. . Copyright holder, funder.","code":""},{"path":"https://tidyselect.r-lib.org/dev/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"Henry L, Wickham H (2024). tidyselect: Select Set Strings. R package version 1.2.1.9000, https://github.com/r-lib/tidyselect, https://tidyselect.r-lib.org.","code":"@Manual{, title = {tidyselect: Select from a Set of Strings}, author = {Lionel Henry and Hadley Wickham}, year = {2024}, note = {R package version 1.2.1.9000, https://github.com/r-lib/tidyselect}, url = {https://tidyselect.r-lib.org}, }"},{"path":[]},{"path":"https://tidyselect.r-lib.org/dev/index.html","id":"overview","dir":"","previous_headings":"","what":"Overview","title":"Select from a Set of Strings","text":"tidyselect package backend functions like dplyr::select() dplyr::pull() well several tidyr verbs. allows create selecting verbs consistent tidyverse packages. learn selection syntax user dplyr tidyr, read user-friendly ?language reference. learn implement tidyselect functions, read vignette(\"tidyselect\"). learn exactly tidyselect syntax interpreted, read technical description vignette(\"syntax\").","code":""},{"path":"https://tidyselect.r-lib.org/dev/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Select from a Set of Strings","text":"Generally, tidyselect installed automatically packages need . need install manually reason, can get :","code":"install.packages(\"tidyselect\")"},{"path":"https://tidyselect.r-lib.org/dev/index.html","id":"code-of-conduct","dir":"","previous_headings":"","what":"Code of Conduct","title":"Select from a Set of Strings","text":"Please note tidyselect project released Contributor Code Conduct. contributing project, agree abide terms.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/all_of.html","id":null,"dir":"Reference","previous_headings":"","what":"Select variables from character vectors — all_of","title":"Select variables from character vectors — all_of","text":"selection helpers select variables contained character vector. especially useful programming selecting functions. all_of() strict selection. variables character vector missing, error thrown. any_of() check missing variables. especially useful negative selections, like make sure variable removed. order selected columns determined order vector.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/all_of.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Select variables from character vectors — all_of","text":"","code":"all_of(x) any_of(x, ..., vars = NULL)"},{"path":"https://tidyselect.r-lib.org/dev/reference/all_of.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Select variables from character vectors — all_of","text":"x vector character names numeric locations. ... dots future extensions must empty. vars character vector variable names. supplied, variables taken current selection context (established functions like select() pivot_longer()).","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/all_of.html","id":"examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Select variables from character vectors — all_of","text":"Selection helpers can used functions like dplyr::select() tidyr::pivot_longer(). first attach tidyverse: common names variables vector. refer variables selecting function, use all_of(): variables missing data frame, error: Use any_of() allow missing variables: any_of() especially useful remove variables data frame calling cause error: Supply named vectors all_of() any_of() select rename columns time:","code":"library(tidyverse) # For better printing iris <- as_tibble(iris) vars <- c(\"Sepal.Length\", \"Sepal.Width\") iris[, vars] #> # A tibble: 150 x 2 #> Sepal.Length Sepal.Width #> #> 1 5.1 3.5 #> 2 4.9 3 #> 3 4.7 3.2 #> 4 4.6 3.1 #> # i 146 more rows iris %>% select(all_of(vars)) #> # A tibble: 150 x 2 #> Sepal.Length Sepal.Width #> #> 1 5.1 3.5 #> 2 4.9 3 #> 3 4.7 3.2 #> 4 4.6 3.1 #> # i 146 more rows iris %>% pivot_longer(all_of(vars)) #> # A tibble: 300 x 5 #> Petal.Length Petal.Width Species name value #> #> 1 1.4 0.2 setosa Sepal.Length 5.1 #> 2 1.4 0.2 setosa Sepal.Width 3.5 #> 3 1.4 0.2 setosa Sepal.Length 4.9 #> 4 1.4 0.2 setosa Sepal.Width 3 #> # i 296 more rows starwars %>% select(all_of(vars)) #> Error: #> i In argument: `all_of(vars)`. #> Caused by error in `all_of()`: #> ! Can't subset elements that don't exist. #> x Elements `Sepal.Length` and `Sepal.Width` don't exist. starwars %>% select(any_of(vars)) #> # A tibble: 87 x 0 iris %>% select(-any_of(vars)) #> # A tibble: 150 x 3 #> Petal.Length Petal.Width Species #> #> 1 1.4 0.2 setosa #> 2 1.4 0.2 setosa #> 3 1.3 0.2 setosa #> 4 1.5 0.2 setosa #> # i 146 more rows iris %>% select(-any_of(vars)) %>% select(-any_of(vars)) #> # A tibble: 150 x 3 #> Petal.Length Petal.Width Species #> #> 1 1.4 0.2 setosa #> 2 1.4 0.2 setosa #> 3 1.3 0.2 setosa #> 4 1.5 0.2 setosa #> # i 146 more rows colors <- c(color_of_hair = \"hair_color\", color_of_eyes = \"eye_color\") starwars %>% select(all_of(colors)) #> # A tibble: 87 x 2 #> color_of_hair color_of_eyes #> #> 1 blond blue #> 2 yellow #> 3 red #> 4 none yellow #> # i 83 more rows"},{"path":[]},{"path":"https://tidyselect.r-lib.org/dev/reference/args_tidy_select.html","id":null,"dir":"Reference","previous_headings":"","what":"Argument type: tidy-select — args_tidy_select","title":"Argument type: tidy-select — args_tidy_select","text":"page describes argument modifier indicates argument supports tidy selections. Tidy selection provides concise dialect R selecting variables based names properties. Tidy selection variant tidy evaluation. means inside functions, tidy-select arguments require special attention, described Indirection section . never heard tidy evaluation , start vignette(\"programming\").","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/args_tidy_select.html","id":"overview-of-selection-features","dir":"Reference","previous_headings":"","what":"Overview of selection features","title":"Argument type: tidy-select — args_tidy_select","text":"Tidyverse selections implement dialect R operators make easy select variables: : selecting range consecutive variables. ! taking complement set variables. & | selecting intersection union two sets variables. c() combining selections. addition, can use selection helpers. helpers select specific columns: everything(): Matches variables. last_col(): Select last variable, possibly offset. helpers select variables matching patterns names: starts_with(): Starts prefix. ends_with(): Ends suffix. contains(): Contains literal string. matches(): Matches regular expression. num_range(): Matches numerical range like x01, x02, x03. variables stored character vector: all_of(): Matches variable names character vector. names must present, otherwise --bounds error thrown. any_of(): all_of(), except error thrown names exist. using predicate function: (): Applies function variables selects function returns TRUE.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/args_tidy_select.html","id":"indirection","dir":"Reference","previous_headings":"","what":"Indirection","title":"Argument type: tidy-select — args_tidy_select","text":"two main cases: character vector column names, use all_of() any_of(), depending whether want unknown variable names cause error, e.g. select(df, all_of(vars)), select(df, !any_of(vars)). want user able supply tidyselect specification function argument, embrace function argument, e.g. select(df, {{ vars }}).","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/eval_relocate.html","id":null,"dir":"Reference","previous_headings":"","what":"Evaluate an expression to relocate variables — eval_relocate","title":"Evaluate an expression to relocate variables — eval_relocate","text":"eval_relocate() variant eval_select() moves selection new location. Either can provided specify move selection . powers dplyr::relocate().","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/eval_relocate.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Evaluate an expression to relocate variables — eval_relocate","text":"","code":"eval_relocate( expr, data, ..., before = NULL, after = NULL, strict = TRUE, name_spec = NULL, allow_rename = TRUE, allow_empty = TRUE, allow_predicates = TRUE, before_arg = \"before\", after_arg = \"after\", env = caller_env(), error_arg = NULL, error_call = caller_env() )"},{"path":"https://tidyselect.r-lib.org/dev/reference/eval_relocate.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Evaluate an expression to relocate variables — eval_relocate","text":"expr Defused R code describing selection according tidyselect syntax. data named list, data frame, atomic vector. Technically, data can vector names() \"[[\" implementations. ... dots future extensions must empty. , Defused R code describing selection according tidyselect syntax. selection represents destination selection provided expr. Supplying neither move selection left-hand side. Supplying error. strict TRUE, --bounds errors thrown expr attempts select rename variable exist. FALSE, failed selections renamings ignored. name_spec name specification describing combine propagate names. used case nested c() expressions like c(foo = c(bar = starts_with(\"foo\"))). See name_spec argument vctrs::vec_c() description valid name specs. allow_rename TRUE (default), renaming syntax c(foo = bar) allowed. FALSE, causes error. useful implement purely selective behaviour. allow_empty TRUE (default), ok expr result empty selection. FALSE, error expr yields empty selection. allow_predicates TRUE (default), ok expr use predicates (.e. ()). FALSE, error expr uses predicate. automatically set FALSE data support predicates (determined tidyselect_data_has_predicates()). before_arg, after_arg Argument names . used error messages. env environment evaluate expr. Discarded expr quosure. error_arg Argument names expr. used error messages. (can use \"...\" expr = c(...)). error_call execution environment currently running function, e.g. caller_env(). function mentioned error messages source error. See call argument abort() information.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/eval_relocate.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Evaluate an expression to relocate variables — eval_relocate","text":"named vector numeric locations length equal length(data). position data represented exactly . names normally input data, except user supplied named selections c(). latter case, names reflect new names chosen user.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/eval_relocate.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Evaluate an expression to relocate variables — eval_relocate","text":"","code":"library(rlang) # Interpret defused code as a request to relocate x <- expr(c(mpg, disp)) after <- expr(wt) eval_relocate(x, mtcars, after = after) #> cyl hp drat wt mpg disp qsec vs am gear carb #> 2 4 5 6 1 3 7 8 9 10 11 # Supplying neither `before` nor `after` will move the selection to the # left-hand side eval_relocate(x, mtcars) #> mpg disp cyl hp drat wt qsec vs am gear carb #> 1 3 2 4 5 6 7 8 9 10 11 # Within a function, use `enquo()` to defuse a single argument. # Note that `before` and `after` must also be defused with `enquo()`. my_relocator <- function(x, expr, before = NULL, after = NULL) { eval_relocate(enquo(expr), x, before = enquo(before), after = enquo(after)) } my_relocator(mtcars, vs, before = hp) #> mpg cyl disp vs hp drat wt qsec am gear carb #> 1 2 3 8 4 5 6 7 9 10 11 # Here is an example of using `eval_relocate()` to implement `relocate()`. # Note that the dots are passed on as a defused call to `c(...)`. relocate <- function(.x, ..., .before = NULL, .after = NULL) { pos <- eval_relocate( expr(c(...)), .x, before = enquo(.before), after = enquo(.after) ) set_names(.x[pos], names(pos)) } relocate(mtcars, vs, .before = hp) #> mpg cyl disp vs hp drat wt qsec am gear carb #> Mazda RX4 21.0 6 160.0 0 110 3.90 2.620 16.46 1 4 4 #> Mazda RX4 Wag 21.0 6 160.0 0 110 3.90 2.875 17.02 1 4 4 #> Datsun 710 22.8 4 108.0 1 93 3.85 2.320 18.61 1 4 1 #> Hornet 4 Drive 21.4 6 258.0 1 110 3.08 3.215 19.44 0 3 1 #> Hornet Sportabout 18.7 8 360.0 0 175 3.15 3.440 17.02 0 3 2 #> Valiant 18.1 6 225.0 1 105 2.76 3.460 20.22 0 3 1 #> Duster 360 14.3 8 360.0 0 245 3.21 3.570 15.84 0 3 4 #> Merc 240D 24.4 4 146.7 1 62 3.69 3.190 20.00 0 4 2 #> Merc 230 22.8 4 140.8 1 95 3.92 3.150 22.90 0 4 2 #> Merc 280 19.2 6 167.6 1 123 3.92 3.440 18.30 0 4 4 #> Merc 280C 17.8 6 167.6 1 123 3.92 3.440 18.90 0 4 4 #> Merc 450SE 16.4 8 275.8 0 180 3.07 4.070 17.40 0 3 3 #> Merc 450SL 17.3 8 275.8 0 180 3.07 3.730 17.60 0 3 3 #> Merc 450SLC 15.2 8 275.8 0 180 3.07 3.780 18.00 0 3 3 #> Cadillac Fleetwood 10.4 8 472.0 0 205 2.93 5.250 17.98 0 3 4 #> Lincoln Continental 10.4 8 460.0 0 215 3.00 5.424 17.82 0 3 4 #> Chrysler Imperial 14.7 8 440.0 0 230 3.23 5.345 17.42 0 3 4 #> Fiat 128 32.4 4 78.7 1 66 4.08 2.200 19.47 1 4 1 #> Honda Civic 30.4 4 75.7 1 52 4.93 1.615 18.52 1 4 2 #> Toyota Corolla 33.9 4 71.1 1 65 4.22 1.835 19.90 1 4 1 #> Toyota Corona 21.5 4 120.1 1 97 3.70 2.465 20.01 0 3 1 #> Dodge Challenger 15.5 8 318.0 0 150 2.76 3.520 16.87 0 3 2 #> AMC Javelin 15.2 8 304.0 0 150 3.15 3.435 17.30 0 3 2 #> Camaro Z28 13.3 8 350.0 0 245 3.73 3.840 15.41 0 3 4 #> Pontiac Firebird 19.2 8 400.0 0 175 3.08 3.845 17.05 0 3 2 #> Fiat X1-9 27.3 4 79.0 1 66 4.08 1.935 18.90 1 4 1 #> Porsche 914-2 26.0 4 120.3 0 91 4.43 2.140 16.70 1 5 2 #> Lotus Europa 30.4 4 95.1 1 113 3.77 1.513 16.90 1 5 2 #> Ford Pantera L 15.8 8 351.0 0 264 4.22 3.170 14.50 1 5 4 #> Ferrari Dino 19.7 6 145.0 0 175 3.62 2.770 15.50 1 5 6 #> Maserati Bora 15.0 8 301.0 0 335 3.54 3.570 14.60 1 5 8 #> Volvo 142E 21.4 4 121.0 1 109 4.11 2.780 18.60 1 4 2 relocate(mtcars, starts_with(\"d\"), .after = last_col()) #> mpg cyl hp wt qsec vs am gear carb disp drat #> Mazda RX4 21.0 6 110 2.620 16.46 0 1 4 4 160.0 3.90 #> Mazda RX4 Wag 21.0 6 110 2.875 17.02 0 1 4 4 160.0 3.90 #> Datsun 710 22.8 4 93 2.320 18.61 1 1 4 1 108.0 3.85 #> Hornet 4 Drive 21.4 6 110 3.215 19.44 1 0 3 1 258.0 3.08 #> Hornet Sportabout 18.7 8 175 3.440 17.02 0 0 3 2 360.0 3.15 #> Valiant 18.1 6 105 3.460 20.22 1 0 3 1 225.0 2.76 #> Duster 360 14.3 8 245 3.570 15.84 0 0 3 4 360.0 3.21 #> Merc 240D 24.4 4 62 3.190 20.00 1 0 4 2 146.7 3.69 #> Merc 230 22.8 4 95 3.150 22.90 1 0 4 2 140.8 3.92 #> Merc 280 19.2 6 123 3.440 18.30 1 0 4 4 167.6 3.92 #> Merc 280C 17.8 6 123 3.440 18.90 1 0 4 4 167.6 3.92 #> Merc 450SE 16.4 8 180 4.070 17.40 0 0 3 3 275.8 3.07 #> Merc 450SL 17.3 8 180 3.730 17.60 0 0 3 3 275.8 3.07 #> Merc 450SLC 15.2 8 180 3.780 18.00 0 0 3 3 275.8 3.07 #> Cadillac Fleetwood 10.4 8 205 5.250 17.98 0 0 3 4 472.0 2.93 #> Lincoln Continental 10.4 8 215 5.424 17.82 0 0 3 4 460.0 3.00 #> Chrysler Imperial 14.7 8 230 5.345 17.42 0 0 3 4 440.0 3.23 #> Fiat 128 32.4 4 66 2.200 19.47 1 1 4 1 78.7 4.08 #> Honda Civic 30.4 4 52 1.615 18.52 1 1 4 2 75.7 4.93 #> Toyota Corolla 33.9 4 65 1.835 19.90 1 1 4 1 71.1 4.22 #> Toyota Corona 21.5 4 97 2.465 20.01 1 0 3 1 120.1 3.70 #> Dodge Challenger 15.5 8 150 3.520 16.87 0 0 3 2 318.0 2.76 #> AMC Javelin 15.2 8 150 3.435 17.30 0 0 3 2 304.0 3.15 #> Camaro Z28 13.3 8 245 3.840 15.41 0 0 3 4 350.0 3.73 #> Pontiac Firebird 19.2 8 175 3.845 17.05 0 0 3 2 400.0 3.08 #> Fiat X1-9 27.3 4 66 1.935 18.90 1 1 4 1 79.0 4.08 #> Porsche 914-2 26.0 4 91 2.140 16.70 0 1 5 2 120.3 4.43 #> Lotus Europa 30.4 4 113 1.513 16.90 1 1 5 2 95.1 3.77 #> Ford Pantera L 15.8 8 264 3.170 14.50 0 1 5 4 351.0 4.22 #> Ferrari Dino 19.7 6 175 2.770 15.50 0 1 5 6 145.0 3.62 #> Maserati Bora 15.0 8 335 3.570 14.60 0 1 5 8 301.0 3.54 #> Volvo 142E 21.4 4 109 2.780 18.60 1 1 4 2 121.0 4.11"},{"path":"https://tidyselect.r-lib.org/dev/reference/eval_select.html","id":null,"dir":"Reference","previous_headings":"","what":"Evaluate an expression with tidyselect semantics — eval_rename","title":"Evaluate an expression with tidyselect semantics — eval_rename","text":"eval_select() eval_rename() evaluate defused R code (.e. quoted expressions) according special rules tidyselect syntax. power functions like dplyr::select(), dplyr::rename(), tidyr::pivot_longer(). See Get started vignette learn use eval_select() eval_rename() packages.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/eval_select.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Evaluate an expression with tidyselect semantics — eval_rename","text":"","code":"eval_rename( expr, data, env = caller_env(), ..., strict = TRUE, name_spec = NULL, allow_predicates = TRUE, error_call = caller_env() ) eval_select( expr, data, env = caller_env(), ..., include = NULL, exclude = NULL, strict = TRUE, name_spec = NULL, allow_rename = TRUE, allow_empty = TRUE, allow_predicates = TRUE, error_arg = NULL, error_call = caller_env() )"},{"path":"https://tidyselect.r-lib.org/dev/reference/eval_select.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Evaluate an expression with tidyselect semantics — eval_rename","text":"expr Defused R code describing selection according tidyselect syntax. data named list, data frame, atomic vector. Technically, data can vector names() \"[[\" implementations. env environment evaluate expr. Discarded expr quosure. ... dots future extensions must empty. strict TRUE, --bounds errors thrown expr attempts select rename variable exist. FALSE, failed selections renamings ignored. name_spec name specification describing combine propagate names. used case nested c() expressions like c(foo = c(bar = starts_with(\"foo\"))). See name_spec argument vctrs::vec_c() description valid name specs. allow_predicates TRUE (default), ok expr use predicates (.e. ()). FALSE, error expr uses predicate. automatically set FALSE data support predicates (determined tidyselect_data_has_predicates()). error_call execution environment currently running function, e.g. caller_env(). function mentioned error messages source error. See call argument abort() information. include, exclude Character vector column names always include exclude selection. allow_rename TRUE (default), renaming syntax c(foo = bar) allowed. FALSE, causes error. useful implement purely selective behaviour. allow_empty TRUE (default), ok expr result empty selection. FALSE, error expr yields empty selection. error_arg Argument names expr. used error messages. (can use \"...\" expr = c(...)).","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/eval_select.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Evaluate an expression with tidyselect semantics — eval_rename","text":"named vector numeric locations, one selected elements. names normally input data, except user supplied named selections c(). latter case, names reflect new names chosen user. given element may selected multiple times different names, case vector might contain duplicate locations.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/eval_select.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Evaluate an expression with tidyselect semantics — eval_rename","text":"select rename variants take types inputs type return value. However eval_rename() extra constraints. requires named inputs, fail data frame column renamed another existing column name. See selecting versus renaming section syntax vignette description differences.","code":""},{"path":[]},{"path":"https://tidyselect.r-lib.org/dev/reference/eval_select.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Evaluate an expression with tidyselect semantics — eval_rename","text":"","code":"library(rlang) # Interpret defused code as selection: x <- expr(mpg:cyl) eval_select(x, mtcars) #> mpg cyl #> 1 2 # Interpret defused code as a renaming selection. All inputs must # be named within `c()`: try(eval_rename(expr(mpg), mtcars)) #> Error in eval(expr, envir) : All renaming inputs must be named. eval_rename(expr(c(foo = mpg)), mtcars) #> foo #> 1 # Within a function, use `enquo()` to defuse one argument: my_function <- function(x, expr) { eval_select(enquo(expr), x) } # If your function takes dots, evaluate a defused call to `c(...)` # with `expr(c(...))`: my_function <- function(.x, ...) { eval_select(expr(c(...)), .x) } # If your function takes dots and a named argument, use `{{ }}` # inside the defused expression to tunnel it inside the tidyselect DSL: my_function <- function(.x, .expr, ...) { eval_select(expr(c({{ .expr }}, ...)), .x) } # Note that the trick above works because `expr({{ arg }})` is the # same as `enquo(arg)`. # Supply `error_arg` to improve the error message in case of # unexpected empty selection: select_not_empty <- function(x, cols) { eval_select(expr = enquo(cols), data = x, allow_empty = FALSE, error_arg = \"cols\") } try(select_not_empty(mtcars, cols = starts_with(\"vs2\"))) #> Error in select_not_empty(mtcars, cols = starts_with(\"vs2\")) : #> `cols` must select at least one column. # The evaluators return a named vector of locations. Here are # examples of using these location vectors to implement `select()` # and `rename()`: select <- function(.x, ...) { pos <- eval_select(expr(c(...)), .x) set_names(.x[pos], names(pos)) } rename <- function(.x, ...) { pos <- eval_rename(expr(c(...)), .x) names(.x)[pos] <- names(pos) .x } select(mtcars, mpg:cyl) #> mpg cyl #> Mazda RX4 21.0 6 #> Mazda RX4 Wag 21.0 6 #> Datsun 710 22.8 4 #> Hornet 4 Drive 21.4 6 #> Hornet Sportabout 18.7 8 #> Valiant 18.1 6 #> Duster 360 14.3 8 #> Merc 240D 24.4 4 #> Merc 230 22.8 4 #> Merc 280 19.2 6 #> Merc 280C 17.8 6 #> Merc 450SE 16.4 8 #> Merc 450SL 17.3 8 #> Merc 450SLC 15.2 8 #> Cadillac Fleetwood 10.4 8 #> Lincoln Continental 10.4 8 #> Chrysler Imperial 14.7 8 #> Fiat 128 32.4 4 #> Honda Civic 30.4 4 #> Toyota Corolla 33.9 4 #> Toyota Corona 21.5 4 #> Dodge Challenger 15.5 8 #> AMC Javelin 15.2 8 #> Camaro Z28 13.3 8 #> Pontiac Firebird 19.2 8 #> Fiat X1-9 27.3 4 #> Porsche 914-2 26.0 4 #> Lotus Europa 30.4 4 #> Ford Pantera L 15.8 8 #> Ferrari Dino 19.7 6 #> Maserati Bora 15.0 8 #> Volvo 142E 21.4 4 rename(mtcars, foo = mpg) #> foo cyl disp hp drat wt qsec vs am gear carb #> Mazda RX4 21.0 6 160.0 110 3.90 2.620 16.46 0 1 4 4 #> Mazda RX4 Wag 21.0 6 160.0 110 3.90 2.875 17.02 0 1 4 4 #> Datsun 710 22.8 4 108.0 93 3.85 2.320 18.61 1 1 4 1 #> Hornet 4 Drive 21.4 6 258.0 110 3.08 3.215 19.44 1 0 3 1 #> Hornet Sportabout 18.7 8 360.0 175 3.15 3.440 17.02 0 0 3 2 #> Valiant 18.1 6 225.0 105 2.76 3.460 20.22 1 0 3 1 #> Duster 360 14.3 8 360.0 245 3.21 3.570 15.84 0 0 3 4 #> Merc 240D 24.4 4 146.7 62 3.69 3.190 20.00 1 0 4 2 #> Merc 230 22.8 4 140.8 95 3.92 3.150 22.90 1 0 4 2 #> Merc 280 19.2 6 167.6 123 3.92 3.440 18.30 1 0 4 4 #> Merc 280C 17.8 6 167.6 123 3.92 3.440 18.90 1 0 4 4 #> Merc 450SE 16.4 8 275.8 180 3.07 4.070 17.40 0 0 3 3 #> Merc 450SL 17.3 8 275.8 180 3.07 3.730 17.60 0 0 3 3 #> Merc 450SLC 15.2 8 275.8 180 3.07 3.780 18.00 0 0 3 3 #> Cadillac Fleetwood 10.4 8 472.0 205 2.93 5.250 17.98 0 0 3 4 #> Lincoln Continental 10.4 8 460.0 215 3.00 5.424 17.82 0 0 3 4 #> Chrysler Imperial 14.7 8 440.0 230 3.23 5.345 17.42 0 0 3 4 #> Fiat 128 32.4 4 78.7 66 4.08 2.200 19.47 1 1 4 1 #> Honda Civic 30.4 4 75.7 52 4.93 1.615 18.52 1 1 4 2 #> Toyota Corolla 33.9 4 71.1 65 4.22 1.835 19.90 1 1 4 1 #> Toyota Corona 21.5 4 120.1 97 3.70 2.465 20.01 1 0 3 1 #> Dodge Challenger 15.5 8 318.0 150 2.76 3.520 16.87 0 0 3 2 #> AMC Javelin 15.2 8 304.0 150 3.15 3.435 17.30 0 0 3 2 #> Camaro Z28 13.3 8 350.0 245 3.73 3.840 15.41 0 0 3 4 #> Pontiac Firebird 19.2 8 400.0 175 3.08 3.845 17.05 0 0 3 2 #> Fiat X1-9 27.3 4 79.0 66 4.08 1.935 18.90 1 1 4 1 #> Porsche 914-2 26.0 4 120.3 91 4.43 2.140 16.70 0 1 5 2 #> Lotus Europa 30.4 4 95.1 113 3.77 1.513 16.90 1 1 5 2 #> Ford Pantera L 15.8 8 351.0 264 4.22 3.170 14.50 0 1 5 4 #> Ferrari Dino 19.7 6 145.0 175 3.62 2.770 15.50 0 1 5 6 #> Maserati Bora 15.0 8 301.0 335 3.54 3.570 14.60 0 1 5 8 #> Volvo 142E 21.4 4 121.0 109 4.11 2.780 18.60 1 1 4 2"},{"path":"https://tidyselect.r-lib.org/dev/reference/everything.html","id":null,"dir":"Reference","previous_headings":"","what":"Select all variables or the last variable — everything","title":"Select all variables or the last variable — everything","text":"functions selection helpers. everything() selects variable. also useful combination tidyselect operators. last_col() selects last variable.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/everything.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Select all variables or the last variable — everything","text":"","code":"everything(vars = NULL) last_col(offset = 0L, vars = NULL)"},{"path":"https://tidyselect.r-lib.org/dev/reference/everything.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Select all variables or the last variable — everything","text":"vars character vector variable names. supplied, variables taken current selection context (established functions like select() pivot_longer()). offset Set n select nth var end.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/everything.html","id":"examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Select all variables or the last variable — everything","text":"Selection helpers can used functions like dplyr::select() tidyr::pivot_longer(). first attach tidyverse: Use everything() select variables: Use last_col() select last variable: Supply offset n select variable located n positions end:","code":"library(tidyverse) # For better printing iris <- as_tibble(iris) mtcars <- as_tibble(mtcars) iris %>% select(everything()) #> # A tibble: 150 x 5 #> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> #> 1 5.1 3.5 1.4 0.2 setosa #> 2 4.9 3 1.4 0.2 setosa #> 3 4.7 3.2 1.3 0.2 setosa #> 4 4.6 3.1 1.5 0.2 setosa #> # i 146 more rows mtcars %>% pivot_longer(everything()) #> # A tibble: 352 x 2 #> name value #> #> 1 mpg 21 #> 2 cyl 6 #> 3 disp 160 #> 4 hp 110 #> # i 348 more rows iris %>% select(last_col()) #> # A tibble: 150 x 1 #> Species #> #> 1 setosa #> 2 setosa #> 3 setosa #> 4 setosa #> # i 146 more rows mtcars %>% pivot_longer(last_col()) #> # A tibble: 32 x 12 #> mpg cyl disp hp drat wt qsec vs am gear name value #> #> 1 21 6 160 110 3.9 2.62 16.5 0 1 4 carb 4 #> 2 21 6 160 110 3.9 2.88 17.0 0 1 4 carb 4 #> 3 22.8 4 108 93 3.85 2.32 18.6 1 1 4 carb 1 #> 4 21.4 6 258 110 3.08 3.22 19.4 1 0 3 carb 1 #> # i 28 more rows mtcars %>% select(1:last_col(5)) #> # A tibble: 32 x 6 #> mpg cyl disp hp drat wt #> #> 1 21 6 160 110 3.9 2.62 #> 2 21 6 160 110 3.9 2.88 #> 3 22.8 4 108 93 3.85 2.32 #> 4 21.4 6 258 110 3.08 3.22 #> # i 28 more rows"},{"path":[]},{"path":[]},{"path":"https://tidyselect.r-lib.org/dev/reference/faq-external-vector.html","id":"ambiguity-between-columns-and-external-variables","dir":"Reference","previous_headings":"","what":"Ambiguity between columns and external variables","title":"FAQ - Note: Using an external vector in selections is ambiguous — faq-external-vector","text":"selecting functions like dplyr::select() tidyr::pivot_longer(), can refer variables name: historical reasons, also possible refer external vector variable names. get correct result, warning informing selecting external variable ambiguous clear whether want data frame column external object. decided deprecate particular approach using external vectors introduce ambiguity. Imagine data frame contains column name external variable. different objects isn’t problem context forces specific find vars: selection context however, column wins:","code":"mtcars %>% select(cyl, am, vs) #> # A tibble: 32 x 3 #> cyl am vs #> #> 1 6 1 0 #> 2 6 1 0 #> 3 4 1 1 #> 4 6 0 1 #> # i 28 more rows mtcars %>% select(mpg:disp) #> # A tibble: 32 x 3 #> mpg cyl disp #> #> 1 21 6 160 #> 2 21 6 160 #> 3 22.8 4 108 #> 4 21.4 6 258 #> # i 28 more rows vars <- c(\"cyl\", \"am\", \"vs\") result <- mtcars %>% select(vars) #> Warning: Using an external vector in selections was deprecated in tidyselect 1.1.0. #> i Please use `all_of()` or `any_of()` instead. #> i See . #> This warning is displayed once every 8 hours. #> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was #> generated. some_df <- mtcars[1:4, ] some_df$vars <- 1:nrow(some_df) vars #> [1] \"cyl\" \"am\" \"vs\" some_df$vars #> [1] 1 2 3 4 some_df %>% select(vars) #> # A tibble: 4 x 1 #> vars #> #> 1 1 #> 2 2 #> 3 3 #> 4 4"},{"path":"https://tidyselect.r-lib.org/dev/reference/faq-external-vector.html","id":"fixing-the-ambiguity","dir":"Reference","previous_headings":"","what":"Fixing the ambiguity","title":"FAQ - Note: Using an external vector in selections is ambiguous — faq-external-vector","text":"make selection code robust silence message, use all_of() force external vector: information comments , please see Github issue tracking deprecation process.","code":"some_df %>% select(all_of(vars)) #> # A tibble: 4 x 3 #> cyl am vs #> #> 1 6 1 0 #> 2 6 1 0 #> 3 4 1 1 #> 4 6 0 1"},{"path":"https://tidyselect.r-lib.org/dev/reference/faq-selection-context.html","id":null,"dir":"Reference","previous_headings":"","what":"FAQ - Error: Must be used within a selecting function — faq-selection-context","title":"FAQ - Error: Must be used within a selecting function — faq-selection-context","text":"Functions like starts_with(), contains() matches() selection helpers work selection context, e.g. dplyr::select() cols argument tidyr::pivot_longer(). Using selection helper anywhere else results error: see error, may used selection helper wrong place, possibly result typo (e.g. misplaced comma wrong argument name). Alternatively, may deliberately trying reduce duplication code extracting selection variable: make work ’ll need two things: Wrap whole thing function Use any_of() all_of() instead bare variable names","code":"starts_with(\"foo\") #> Error: #> ! `starts_with()` must be used within a *selecting* function. #> i See for #> details. mtcars[contains(\"foo\")] #> Error: #> ! `contains()` must be used within a *selecting* function. #> i See for #> details. subset(mtcars, select = matches(\"foo\")) #> Error: #> ! `matches()` must be used within a *selecting* function. #> i See for #> details. my_vars <- c(name, species, ends_with(\"color\")) #> Error: object 'name' not found my_vars <- function() { c(any_of(c(\"name\", \"species\")), ends_with(\"color\")) } dplyr::select(starwars, my_vars()) #> # A tibble: 87 x 5 #> name species hair_color skin_color eye_color #> #> 1 Luke Skywalker Human blond fair blue #> 2 C-3PO Droid gold yellow #> 3 R2-D2 Droid white, blue red #> 4 Darth Vader Human none white yellow #> # i 83 more rows"},{"path":[]},{"path":"https://tidyselect.r-lib.org/dev/reference/language.html","id":"overview-of-selection-features-","dir":"Reference","previous_headings":"","what":"Overview of selection features:","title":"Selection language — language","text":"Tidyverse selections implement dialect R operators make easy select variables: : selecting range consecutive variables. ! taking complement set variables. & | selecting intersection union two sets variables. c() combining selections. addition, can use selection helpers. helpers select specific columns: everything(): Matches variables. last_col(): Select last variable, possibly offset. helpers select variables matching patterns names: starts_with(): Starts prefix. ends_with(): Ends suffix. contains(): Contains literal string. matches(): Matches regular expression. num_range(): Matches numerical range like x01, x02, x03. variables stored character vector: all_of(): Matches variable names character vector. names must present, otherwise --bounds error thrown. any_of(): all_of(), except error thrown names exist. using predicate function: (): Applies function variables selects function returns TRUE.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/language.html","id":"simple-examples","dir":"Reference","previous_headings":"","what":"Simple examples","title":"Selection language — language","text":"show usage basic selection operators. See specific help pages learn helpers like starts_with(). selection language can used functions like dplyr::select() tidyr::pivot_longer(). first attach tidyverse: Select variables name: Select multiple variables separating commas. Note order columns determined order inputs: Functions like tidyr::pivot_longer() take variables dots. case use c() select multiple variables:","code":"library(tidyverse) # For better printing iris <- as_tibble(iris) starwars %>% select(height) #> # A tibble: 87 x 1 #> height #> #> 1 172 #> 2 167 #> 3 96 #> 4 202 #> # i 83 more rows iris %>% pivot_longer(Sepal.Length) #> # A tibble: 150 x 6 #> Sepal.Width Petal.Length Petal.Width Species name value #> #> 1 3.5 1.4 0.2 setosa Sepal.Length 5.1 #> 2 3 1.4 0.2 setosa Sepal.Length 4.9 #> 3 3.2 1.3 0.2 setosa Sepal.Length 4.7 #> 4 3.1 1.5 0.2 setosa Sepal.Length 4.6 #> # i 146 more rows starwars %>% select(homeworld, height, mass) #> # A tibble: 87 x 3 #> homeworld height mass #> #> 1 Tatooine 172 77 #> 2 Tatooine 167 75 #> 3 Naboo 96 32 #> 4 Tatooine 202 136 #> # i 83 more rows iris %>% pivot_longer(c(Sepal.Length, Petal.Length)) #> # A tibble: 300 x 5 #> Sepal.Width Petal.Width Species name value #> #> 1 3.5 0.2 setosa Sepal.Length 5.1 #> 2 3.5 0.2 setosa Petal.Length 1.4 #> 3 3 0.2 setosa Sepal.Length 4.9 #> 4 3 0.2 setosa Petal.Length 1.4 #> # i 296 more rows"},{"path":"https://tidyselect.r-lib.org/dev/reference/language.html","id":"operators-","dir":"Reference","previous_headings":"","what":"Operators:","title":"Selection language — language","text":": operator selects range consecutive variables: ! operator negates selection: & | take intersection union two selections: take difference two selections, combine & ! operators:","code":"starwars %>% select(name:mass) #> # A tibble: 87 x 3 #> name height mass #> #> 1 Luke Skywalker 172 77 #> 2 C-3PO 167 75 #> 3 R2-D2 96 32 #> 4 Darth Vader 202 136 #> # i 83 more rows starwars %>% select(!(name:mass)) #> # A tibble: 87 x 11 #> hair_color skin_color eye_color birth_year sex gender homeworld species #> #> 1 blond fair blue 19 male masculine Tatooine Human #> 2 gold yellow 112 none masculine Tatooine Droid #> 3 white, blue red 33 none masculine Naboo Droid #> 4 none white yellow 41.9 male masculine Tatooine Human #> # i 83 more rows #> # i 3 more variables: films , vehicles , starships iris %>% select(!c(Sepal.Length, Petal.Length)) #> # A tibble: 150 x 3 #> Sepal.Width Petal.Width Species #> #> 1 3.5 0.2 setosa #> 2 3 0.2 setosa #> 3 3.2 0.2 setosa #> 4 3.1 0.2 setosa #> # i 146 more rows iris %>% select(!ends_with(\"Width\")) #> # A tibble: 150 x 3 #> Sepal.Length Petal.Length Species #> #> 1 5.1 1.4 setosa #> 2 4.9 1.4 setosa #> 3 4.7 1.3 setosa #> 4 4.6 1.5 setosa #> # i 146 more rows iris %>% select(starts_with(\"Petal\") & ends_with(\"Width\")) #> # A tibble: 150 x 1 #> Petal.Width #> #> 1 0.2 #> 2 0.2 #> 3 0.2 #> 4 0.2 #> # i 146 more rows iris %>% select(starts_with(\"Petal\") | ends_with(\"Width\")) #> # A tibble: 150 x 3 #> Petal.Length Petal.Width Sepal.Width #> #> 1 1.4 0.2 3.5 #> 2 1.4 0.2 3 #> 3 1.3 0.2 3.2 #> 4 1.5 0.2 3.1 #> # i 146 more rows iris %>% select(starts_with(\"Petal\") & !ends_with(\"Width\")) #> # A tibble: 150 x 1 #> Petal.Length #> #> 1 1.4 #> 2 1.4 #> 3 1.3 #> 4 1.5 #> # i 146 more rows"},{"path":"https://tidyselect.r-lib.org/dev/reference/language.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Selection language — language","text":"order selected columns determined inputs. all_of(c(\"foo\", \"bar\")) selects \"foo\" first. c(starts_with(\"c\"), starts_with(\"d\")) selects columns starting \"c\" first, columns starting \"d\".","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/one_of.html","id":null,"dir":"Reference","previous_headings":"","what":"Superseded selection helpers — one_of","title":"Superseded selection helpers — one_of","text":"one_of() superseded favour precise any_of() all_of() selectors.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/one_of.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Superseded selection helpers — one_of","text":"","code":"one_of(..., .vars = NULL)"},{"path":"https://tidyselect.r-lib.org/dev/reference/one_of.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Superseded selection helpers — one_of","text":"... One character vectors. .vars character vector variable names. called inside selecting functions like dplyr::select() automatically set names table.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/peek_vars.html","id":null,"dir":"Reference","previous_headings":"","what":"Peek at variables in the selection context — peek_vars","title":"Peek at variables in the selection context — peek_vars","text":"peek_vars() returns vector names variables currently available selection. peek_data() returns whole input vector (available eval_select()). Read Get started examples create selection helpers peek_vars(). variable names selection context registered automatically eval_select() eval_rename() duration evaluation. peek_vars() glue connects selection helpers current selection context.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/peek_vars.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Peek at variables in the selection context — peek_vars","text":"","code":"peek_vars(..., fn = NULL) peek_data(..., fn = NULL)"},{"path":"https://tidyselect.r-lib.org/dev/reference/peek_vars.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Peek at variables in the selection context — peek_vars","text":"... dots future extensions must empty. fn name function use error messages helper used wrong context. supplied, generic error message used instead.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/poke_vars.html","id":null,"dir":"Reference","previous_headings":"","what":"Replace or get current variables — poke_vars","title":"Replace or get current variables — poke_vars","text":"Variables made available select helpers registering special placeholder. scoped_vars() changes current variables sets function exit hook automatically restores previous variables current function returns. with_vars() takes expression evaluated variable context. poke_vars() changes contents placeholder new set variables. returns previous variables invisibly responsibility restore done. expert use . peek_vars() returns variables currently registered. has_vars() returns TRUE variable context set, FALSE otherwise.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/poke_vars.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Replace or get current variables — poke_vars","text":"","code":"poke_vars(vars) scoped_vars(vars, frame = caller_env()) with_vars(vars, expr) has_vars()"},{"path":"https://tidyselect.r-lib.org/dev/reference/poke_vars.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Replace or get current variables — poke_vars","text":"vars character vector variable names. frame frame environment exit hook restoring old variables registered. expr expression evaluated within variable context.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/poke_vars.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Replace or get current variables — poke_vars","text":"poke_vars() scoped_vars(), old variables invisibly. peek_vars(), variables currently registered.","code":""},{"path":[]},{"path":"https://tidyselect.r-lib.org/dev/reference/poke_vars.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Replace or get current variables — poke_vars","text":"","code":"poke_vars(letters) peek_vars() #> [1] \"a\" \"b\" \"c\" \"d\" \"e\" \"f\" \"g\" \"h\" \"i\" \"j\" \"k\" \"l\" \"m\" \"n\" \"o\" \"p\" \"q\" #> [18] \"r\" \"s\" \"t\" \"u\" \"v\" \"w\" \"x\" \"y\" \"z\" # Now that the variables are registered, the helpers can figure out # the locations of elements within the variable vector: all_of(c(\"d\", \"z\")) #> [1] 4 26 # In a function be sure to restore the previous variables. An exit # hook is the best way to do it: fn <- function(vars) { old <- poke_vars(vars) on.exit(poke_vars(old)) all_of(\"d\") } fn(letters) #> [1] 4 fn(letters[3:5]) #> [1] 2 # The previous variables are still registered after fn() was # called: peek_vars() #> [1] \"a\" \"b\" \"c\" \"d\" \"e\" \"f\" \"g\" \"h\" \"i\" \"j\" \"k\" \"l\" \"m\" \"n\" \"o\" \"p\" \"q\" #> [18] \"r\" \"s\" \"t\" \"u\" \"v\" \"w\" \"x\" \"y\" \"z\" # It is recommended to use the scoped variant as it restores the # state automatically when the function returns: fn <- function(vars) { scoped_vars(vars) starts_with(\"r\") } fn(c(\"red\", \"blue\", \"rose\")) #> [1] 1 3 # The with_vars() helper makes it easy to pass an expression that # should be evaluated in a variable context. Thanks to lazy # evaluation, you can just pass the expression argument from your # wrapper to with_vars(): fn <- function(expr) { vars <- c(\"red\", \"blue\", \"rose\") with_vars(vars, expr) } fn(starts_with(\"r\")) #> [1] 1 3"},{"path":"https://tidyselect.r-lib.org/dev/reference/reexports.html","id":null,"dir":"Reference","previous_headings":"","what":"Objects exported from other packages — reexports","title":"Objects exported from other packages — reexports","text":"objects imported packages. Follow links see documentation. rlang enquo, quo, quo_name, quos","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/starts_with.html","id":null,"dir":"Reference","previous_headings":"","what":"Select variables that match a pattern — starts_with","title":"Select variables that match a pattern — starts_with","text":"selection helpers match variables according given pattern. starts_with(): Starts exact prefix. ends_with(): Ends exact suffix. contains(): Contains literal string. matches(): Matches regular expression. num_range(): Matches numerical range like x01, x02, x03.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/starts_with.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Select variables that match a pattern — starts_with","text":"","code":"starts_with(match, ignore.case = TRUE, vars = NULL) ends_with(match, ignore.case = TRUE, vars = NULL) contains(match, ignore.case = TRUE, vars = NULL) matches(match, ignore.case = TRUE, perl = TRUE, vars = NULL) num_range( prefix, range, suffix = \"\", width = NULL, ..., cross = FALSE, vars = NULL )"},{"path":"https://tidyselect.r-lib.org/dev/reference/starts_with.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Select variables that match a pattern — starts_with","text":"match character vector. length > 1, union matches taken. starts_with(), ends_with(), contains() exact match. matches() regular expression, can stringr pattern. ignore.case TRUE, default, ignores case matching names. vars character vector variable names. supplied, variables taken current selection context (established functions like select() pivot_longer()). perl Perl-compatible regexps used? prefix, suffix prefix/suffix added /numeric range. range sequence integers, like 1:5. width Optionally, \"width\" numeric range. example, range 2 gives \"01\", range three \"001\", etc. ... dots future extensions must empty. cross Whether take cartesian product prefix, range, suffix. FALSE, default, arguments recycled using tidyverse rules.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/starts_with.html","id":"examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Select variables that match a pattern — starts_with","text":"Selection helpers can used functions like dplyr::select() tidyr::pivot_longer(). first attach tidyverse: starts_with() selects variables matching prefix ends_with() matches suffix: can supply multiple prefixes suffixes. Note order variables depends order suffixes prefixes: contains() selects columns whose names contain word: starts_with(), ends_with(), contains() use regular expressions. select regexp use matches(): starts_with() selects variables starting prefix. select range, use num_range(). Compare:","code":"library(tidyverse) # For better printing iris <- as_tibble(iris) iris %>% select(starts_with(\"Sepal\")) #> # A tibble: 150 x 2 #> Sepal.Length Sepal.Width #> #> 1 5.1 3.5 #> 2 4.9 3 #> 3 4.7 3.2 #> 4 4.6 3.1 #> # i 146 more rows iris %>% select(ends_with(\"Width\")) #> # A tibble: 150 x 2 #> Sepal.Width Petal.Width #> #> 1 3.5 0.2 #> 2 3 0.2 #> 3 3.2 0.2 #> 4 3.1 0.2 #> # i 146 more rows iris %>% select(starts_with(c(\"Petal\", \"Sepal\"))) #> # A tibble: 150 x 4 #> Petal.Length Petal.Width Sepal.Length Sepal.Width #> #> 1 1.4 0.2 5.1 3.5 #> 2 1.4 0.2 4.9 3 #> 3 1.3 0.2 4.7 3.2 #> 4 1.5 0.2 4.6 3.1 #> # i 146 more rows iris %>% select(ends_with(c(\"Width\", \"Length\"))) #> # A tibble: 150 x 4 #> Sepal.Width Petal.Width Sepal.Length Petal.Length #> #> 1 3.5 0.2 5.1 1.4 #> 2 3 0.2 4.9 1.4 #> 3 3.2 0.2 4.7 1.3 #> 4 3.1 0.2 4.6 1.5 #> # i 146 more rows iris %>% select(contains(\"al\")) #> # A tibble: 150 x 4 #> Sepal.Length Sepal.Width Petal.Length Petal.Width #> #> 1 5.1 3.5 1.4 0.2 #> 2 4.9 3 1.4 0.2 #> 3 4.7 3.2 1.3 0.2 #> 4 4.6 3.1 1.5 0.2 #> # i 146 more rows # [pt] is matched literally: iris %>% select(contains(\"[pt]al\")) #> # A tibble: 150 x 0 # [pt] is interpreted as a regular expression iris %>% select(matches(\"[pt]al\")) #> # A tibble: 150 x 4 #> Sepal.Length Sepal.Width Petal.Length Petal.Width #> #> 1 5.1 3.5 1.4 0.2 #> 2 4.9 3 1.4 0.2 #> 3 4.7 3.2 1.3 0.2 #> 4 4.6 3.1 1.5 0.2 #> # i 146 more rows billboard %>% select(starts_with(\"wk\")) #> # A tibble: 317 x 76 #> wk1 wk2 wk3 wk4 wk5 wk6 wk7 wk8 wk9 wk10 wk11 wk12 wk13 #> #> 1 87 82 72 77 87 94 99 NA NA NA NA NA NA #> 2 91 87 92 NA NA NA NA NA NA NA NA NA NA #> 3 81 70 68 67 66 57 54 53 51 51 51 51 47 #> 4 76 76 72 69 67 65 55 59 62 61 61 59 61 #> # i 313 more rows #> # i 63 more variables: wk14 , wk15 , wk16 , wk17 , #> # wk18 , wk19 , wk20 , wk21 , ... billboard %>% select(num_range(\"wk\", 10:15)) #> # A tibble: 317 x 6 #> wk10 wk11 wk12 wk13 wk14 wk15 #> #> 1 NA NA NA NA NA NA #> 2 NA NA NA NA NA NA #> 3 51 51 51 47 44 38 #> 4 61 61 59 61 66 72 #> # i 313 more rows"},{"path":[]},{"path":"https://tidyselect.r-lib.org/dev/reference/tidyselect-package.html","id":null,"dir":"Reference","previous_headings":"","what":"tidyselect: Select from a Set of Strings — tidyselect-package","title":"tidyselect: Select from a Set of Strings — tidyselect-package","text":"backend selecting functions 'tidyverse'. makes easy implement select-like functions packages way consistent 'tidyverse' interfaces selection.","code":""},{"path":[]},{"path":"https://tidyselect.r-lib.org/dev/reference/tidyselect-package.html","id":"author","dir":"Reference","previous_headings":"","what":"Author","title":"tidyselect: Select from a Set of Strings — tidyselect-package","text":"Maintainer: Lionel Henry lionel@posit.co Authors: Hadley Wickham hadley@posit.co contributors: Posit Software, PBC [copyright holder, funder]","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/tidyselect_data_proxy.html","id":null,"dir":"Reference","previous_headings":"","what":"tidyselect methods for custom types — tidyselect_data_proxy","title":"tidyselect methods for custom types — tidyselect_data_proxy","text":"tidyselect_data_proxy() returns data frame. tidyselect_data_has_predicates() returns TRUE FALSE support predicate functions, return 0-row data frame tidyselect_data_proxy() FALSE tidyselect_data_has_predicates().","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/tidyselect_data_proxy.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"tidyselect methods for custom types — tidyselect_data_proxy","text":"","code":"tidyselect_data_proxy(x) tidyselect_data_has_predicates(x)"},{"path":"https://tidyselect.r-lib.org/dev/reference/tidyselect_data_proxy.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"tidyselect methods for custom types — tidyselect_data_proxy","text":"x data-frame like object passed eval_select(), eval_rename(), friends.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/vars_pull.html","id":null,"dir":"Reference","previous_headings":"","what":"Select variable — vars_pull","title":"Select variable — vars_pull","text":"function powers dplyr::pull() various functions tidyr package. similar vars_select() returns one column name slightly different semantics: allows negative numbers select columns end.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/vars_pull.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Select variable — vars_pull","text":"","code":"vars_pull( vars, var = -1, error_call = caller_env(), error_arg = caller_arg(var) )"},{"path":"https://tidyselect.r-lib.org/dev/reference/vars_pull.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Select variable — vars_pull","text":"vars character vector existing column names. var variable specified : literal variable name positive integer, giving position counting left negative integer, giving position counting right. default returns last column (assumption column created recently). argument taken expression supports quasiquotation (can unquote column names column locations). error_call execution environment currently running function, e.g. caller_env(). function mentioned error messages source error. See call argument abort() information. error_arg argument name string. argument mentioned error messages input origin problem.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/vars_pull.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Select variable — vars_pull","text":"selected column name unnamed string.","code":""},{"path":[]},{"path":"https://tidyselect.r-lib.org/dev/reference/vars_pull.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Select variable — vars_pull","text":"","code":"# It takes its argument by expression: vars_pull(letters, c) #> [1] \"c\" # Negative numbers select from the end: vars_pull(letters, -3) #> [1] \"x\" # You can unquote variables: var <- 10 vars_pull(letters, !!var) #> [1] \"j\""},{"path":"https://tidyselect.r-lib.org/dev/reference/vars_select.html","id":null,"dir":"Reference","previous_headings":"","what":"Select or rename variables — vars_select","title":"Select or rename variables — vars_select","text":"Please use eval_select() eval_rename() instead. See vignette(\"tidyselect\") get started.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/vars_select.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Select or rename variables — vars_select","text":"","code":"vars_select( .vars, ..., .include = character(), .exclude = character(), .strict = TRUE ) vars_rename(.vars, ..., .strict = TRUE)"},{"path":"https://tidyselect.r-lib.org/dev/reference/vars_select.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Select or rename variables — vars_select","text":".vars character vector existing column names. ... Selection inputs. See help selection helpers. .include, .exclude Character vector column names always include/exclude. .strict TRUE, throw error attempt select rename variable exist.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/vars_select.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Select or rename variables — vars_select","text":"named character vector. Values existing column names, names new names.","code":""},{"path":[]},{"path":"https://tidyselect.r-lib.org/dev/reference/vars_select_helpers.html","id":null,"dir":"Reference","previous_headings":"","what":"List of selection helpers — vars_select_helpers","title":"List of selection helpers — vars_select_helpers","text":"list contains selection helpers exported tidyselect. useful wanted embed helpers API without track addition new helpers tidyselect. However selection helpers now always embedded DSL.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/vars_select_helpers.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"List of selection helpers — vars_select_helpers","text":"","code":"vars_select_helpers"},{"path":"https://tidyselect.r-lib.org/dev/reference/vars_select_helpers.html","id":"format","dir":"Reference","previous_headings":"","what":"Format","title":"List of selection helpers — vars_select_helpers","text":"object class list length 11.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/where.html","id":null,"dir":"Reference","previous_headings":"","what":"Select variables with a function — where","title":"Select variables with a function — where","text":"selection helper selects variables function returns TRUE.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/where.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Select variables with a function — where","text":"","code":"where(fn)"},{"path":"https://tidyselect.r-lib.org/dev/reference/where.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Select variables with a function — where","text":"fn function returns TRUE FALSE (technically, predicate function). Can also purrr-like formula.","code":""},{"path":"https://tidyselect.r-lib.org/dev/reference/where.html","id":"examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Select variables with a function — where","text":"Selection helpers can used functions like dplyr::select() tidyr::pivot_longer(). first attach tidyverse: () takes function returns variables function returns TRUE:","code":"library(tidyverse) # For better printing iris <- as_tibble(iris) is.factor(iris[[4]]) #> [1] FALSE is.factor(iris[[5]]) #> [1] TRUE iris %>% select(where(is.factor)) #> # A tibble: 150 x 1 #> Species #> #> 1 setosa #> 2 setosa #> 3 setosa #> 4 setosa #> # i 146 more rows is.numeric(iris[[4]]) #> [1] TRUE is.numeric(iris[[5]]) #> [1] FALSE iris %>% select(where(is.numeric)) #> # A tibble: 150 x 4 #> Sepal.Length Sepal.Width Petal.Length Petal.Width #> #> 1 5.1 3.5 1.4 0.2 #> 2 4.9 3 1.4 0.2 #> 3 4.7 3.2 1.3 0.2 #> 4 4.6 3.1 1.5 0.2 #> # i 146 more rows"},{"path":"https://tidyselect.r-lib.org/dev/reference/where.html","id":"the-formula-shorthand","dir":"Reference","previous_headings":"","what":"The formula shorthand","title":"Select variables with a function — where","text":"can use purrr-like formulas shortcut creating function spot. expressions equivalent: shorthand useful adding logic inline. select numeric variables whose mean greater 3.5:","code":"iris %>% select(where(is.numeric)) #> # A tibble: 150 x 4 #> Sepal.Length Sepal.Width Petal.Length Petal.Width #> #> 1 5.1 3.5 1.4 0.2 #> 2 4.9 3 1.4 0.2 #> 3 4.7 3.2 1.3 0.2 #> 4 4.6 3.1 1.5 0.2 #> # i 146 more rows iris %>% select(where(function(x) is.numeric(x))) #> # A tibble: 150 x 4 #> Sepal.Length Sepal.Width Petal.Length Petal.Width #> #> 1 5.1 3.5 1.4 0.2 #> 2 4.9 3 1.4 0.2 #> 3 4.7 3.2 1.3 0.2 #> 4 4.6 3.1 1.5 0.2 #> # i 146 more rows iris %>% select(where(~ is.numeric(.x))) #> # A tibble: 150 x 4 #> Sepal.Length Sepal.Width Petal.Length Petal.Width #> #> 1 5.1 3.5 1.4 0.2 #> 2 4.9 3 1.4 0.2 #> 3 4.7 3.2 1.3 0.2 #> 4 4.6 3.1 1.5 0.2 #> # i 146 more rows iris %>% select(where(~ is.numeric(.x) && mean(.x) > 3.5)) #> # A tibble: 150 x 2 #> Sepal.Length Petal.Length #> #> 1 5.1 1.4 #> 2 4.9 1.4 #> 3 4.7 1.3 #> 4 4.6 1.5 #> # i 146 more rows"},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"tidyselect-development-version","dir":"Changelog","previous_headings":"","what":"tidyselect (development version)","title":"tidyselect (development version)","text":"matches() now uses perl = TRUE default. makes consitent regular expressions stringr (#330). eval_select() now fails data duplicate names character vector provided input (#346). New args_tidy_select documentation topic. Use following tags document tidyselect arguments functions: eval_select() eval_relocate() gain new error_arg argument can specified throw better error message allow_empty = FALSE allow_rename = FALSE (@olivroy, #327). vars_pull() now also warns using .data (#335). Please use string-quotation programmatic usage, consistently tidyselect contexts. num_range() now recycles arguments using tidyverse rules (#355). addition, gains cross argument allows take cartesian product arguments instead. eval_select() eval_relocate() throw classed error message allow_empty = FALSE (@olivroy, #347).","code":"#' @param ... <[`tidy-select`][tidyselect::args_tidy_select]> *doc* #' @param sel <[`tidy-select`][tidyselect::args_tidy_select]> *doc*"},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"tidyselect-121","dir":"Changelog","previous_headings":"","what":"tidyselect 1.2.1","title":"tidyselect 1.2.1","text":"CRAN release: 2024-03-11 Performance improvements (#337, #338, #339, #341) eval_select() --bounds errors now use verb “select” rather “subset” error message consistency dplyr::select() (#271). Fix CRAN checks.","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"tidyselect-120","dir":"Changelog","previous_headings":"","what":"tidyselect 1.2.0","title":"tidyselect 1.2.0","text":"CRAN release: 2022-10-10","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"new-features-1-2-0","dir":"Changelog","previous_headings":"","what":"New features","title":"tidyselect 1.2.0","text":"New tidyselect_data_proxy() tidyselect_data_has_predicates() allows tidyselect work custom input types (#242). New eval_relocate() moving selection. powers dplyr::relocate() (#232).","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"lifecycle-changes-1-2-0","dir":"Changelog","previous_headings":"","what":"Lifecycle changes","title":"tidyselect 1.2.0","text":"Using all_of() outside tidyselect context now deprecated (#269). future error consistent any_of(). Use .data tidyselect expressions now deprecated cleanly separate tidy-select data-masking. Replace .data$x \"x\" .data[[var]] all_of(var) (#169). Use bare predicates (wrapped ()) indirection (without using all_of()) formally deprecated (#317).","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"minor-improvements-and-bug-fixes-1-2-0","dir":"Changelog","previous_headings":"","what":"Minor improvements and bug fixes","title":"tidyselect 1.2.0","text":"Selection language: any_of() generates informative error supply many arguments (#241). all_of() (like any_of()) returns integer vector make easier combine functions (#270, #294). also fails can’t find variables even strict = FALSE. matches() recognises correctly uses stringr pattern objects (stringr::regex(), stringr::fixed(), etc) (#238). also now works named vectors (#250). num_range() gains suffix argument (#229). () now exported, like select helpers (#201), gives informative errors (#236). eval_select() include now preserves order variables ’re present selection (#224). eval_select() always returns named vector, even renaming permitted (#220). eval_select() eval_relocate() gain new allow_empty argument makes possible forbid empty selections allow_empty = FALSE (#252). eval_select(allow_rename = FALSE) longer fails empty selections (#221, @eutwt) predicate functions (#225). now properly fails partial renaming (#305). peek_var() error now generates hyperlink docs recent RStudio (#289). vars_pull() generates informative error messages (#234, #258, #318) gains error_call error_arg arguments. Errors produced tidyselect now informative. Evaluation errors now chained, child error call set error_call argument eval_select() eval_rename(). ’ve also improved backtraces base errors, done better propagating root error_call vctrs input checkers. tidyselect_verbosity longer used; deprecation messaging now controlled lifecycle_verbosity like packages (#317).","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"tidyselect-112","dir":"Changelog","previous_headings":"","what":"tidyselect 1.1.2","title":"tidyselect 1.1.2","text":"CRAN release: 2022-02-21 Fix CRAN checks. Better compatibility rlang 1.0.0 errors. come soon.","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"tidyselect-111","dir":"Changelog","previous_headings":"","what":"tidyselect 1.1.1","title":"tidyselect 1.1.1","text":"CRAN release: 2021-04-30 Fix CRAN checks. tidyselect re-licensed MIT (#217).","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"tidyselect-110","dir":"Changelog","previous_headings":"","what":"tidyselect 1.1.0","title":"tidyselect 1.1.0","text":"CRAN release: 2020-05-11 Predicate functions must now wrapped (). {r} iris %>% select((.factor)) made change avoid puzzling error messages variable unexpectedly missing data frame corresponding function environment: {r} # Attempts invoke `data()` function data.frame(x = 1) %>% select(data) Now tidyselect correctly complain missing variable rather trying invoke function. compatibility support predicate functions starting 1 version. eval_select() gains allow_rename argument. set FALSE, renaming variables c(foo = bar) syntax error. useful implement purely selective behaviour (#178). Fixed issue preventing repeated deprecation messages tidyselect_verbosity set \"verbose\" (#184). any_of() now preserves order input variables (#186). return value eval_select() now always named, even inputs constant (#173).","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"tidyselect-100","dir":"Changelog","previous_headings":"","what":"tidyselect 1.0.0","title":"tidyselect 1.0.0","text":"CRAN release: 2020-01-27 1.0.0 release tidyselect. features solidly defined implemented syntax, support predicate functions, new boolean operators, much .","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"documentation-1-0-0","dir":"Changelog","previous_headings":"","what":"Documentation","title":"tidyselect 1.0.0","text":"New Get started vignette client packages. Read vignette(\"tidyselect\") https://tidyselect.r-lib.org/articles/tidyselect.html. definition tidyselect language consolidated. technical description now available: https://tidyselect.r-lib.org/articles/syntax.html.","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"breaking-changes-1-0-0","dir":"Changelog","previous_headings":"","what":"Breaking changes","title":"tidyselect 1.0.0","text":"Selecting non-column variables bare names now triggers informative message suggesting use all_of() instead. Referring contextual objects bare name brittle might masked data frame column. Using all_of() safe (#76). tidyselect now uses vctrs validating inputs. changes may reveal programming errors previously silent. may also cause failures unit tests make faulty assumptions content error messages created tidyselect: --bounds errors thrown name doesn’t exist location large input. Logical vectors now fail properly. Selected variables now must unique. previously possible return duplicate selections circumstances. input names can longer contain NA values. Note recommend testthat::verify_output() monitoring error messages thrown packages don’t control. Unlike expect_error(), verify_output() cause CMD check failures error messages changed. See https://www.tidyverse.org/blog/2019/11/testthat-2-3-0/ information.","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"syntax-1-0-0","dir":"Changelog","previous_headings":"","what":"Syntax","title":"tidyselect 1.0.0","text":"boolean operators can now used create selections (#106). ! negates selection. | takes union two selections. & takes intersection two selections. patterns can currently achieved using -, c() intersect() respectively. boolean operators intuitive use. Many thanks Irene Steves (@isteves) suggesting UI. can now use predicate functions selection contexts: feature available functions use legacy interface tidyselect. need updated use new eval_select() function instead vars_select(). Unary - inside nested c() now consistently syntax set difference (#130). Improved support named elements. now possible assign name multiple elements, input data structure doesn’t require unique names (.e. anything data frame). selection engine rewritten support clearer separation data-expressions (calls :, -, c) env-expressions (anything else). means can now safely use expressions type: Even data frame data contains column also named data, subexpression ncol(data) still correctly evaluated. data:ncol(data) expression equivalent 2:3 data looked relevant context without ambiguity: example bit contrived, many realistic cases changes make easier write safe code: {r} select_from <- function(data, var) { data %>% dplyr::select({{ var }} : ncol(data)) } data %>% select_from(data) #> # tibble: 1 x 2 #> data bar #> #> 1 2 3","code":"iris %>% select(is.factor) iris %>% select(is.factor | is.numeric) data %>% select(1:ncol(data)) data %>% pivot_longer(1:ncol(data)) data <- tibble(foo = 1, data = 2, bar = 3) data %>% dplyr::select(data:ncol(data)) #> # A tibble: 1 x 2 #> data bar #> #> 1 2 3"},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"user-facing-improvements-1-0-0","dir":"Changelog","previous_headings":"","what":"User-facing improvements","title":"tidyselect 1.0.0","text":"new selection helpers all_of() any_of() strict variants one_of(). former always fails variables unknown, latter . all_of() safer use expect selected variables exist. any_of() useful cases, instance ensure variables selected : Note all_of() any_of() bit conservative function signature one_of(): accept dots. equivalent one_of(\"\", \"b\") all_of(c(\"\", \"b\")). Selection helpers like all_of() starts_with() now available selection contexts, even haven’t attached search path. visible consequence change now easier use selection functions without attaching host package: still recommended export helpers package users can easily look documentation ?. starts_with(), ends_with(), contains(), matches() now accept vector inputs (#50). instance now equivalent ways selecting variables start either \"\" \"b\": {r} starts_with(c(\"\", \"b\")) starts_with(\"\") | starts_with(\"b\") matches() new argument perl allow Perl-like regular expressions (@fmichonneau, #71) Better support selecting S3 vectors. instance, factors treated characters.","code":"vars <- c(\"Species\", \"Genus\") iris %>% dplyr::select(-any_of(vars)) # Before dplyr::select(mtcars, dplyr::starts_with(\"c\")) # After dplyr::select(mtcars, starts_with(\"c\"))"},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"api-1-0-0","dir":"Changelog","previous_headings":"","what":"API","title":"tidyselect 1.0.0","text":"New eval_select() eval_rename() functions client packages. replace vars_select() vars_rename(), now deprecated. functions: Take full data rather just names. makes possible use function predicates selection context. Return numeric vector locations rather vector names. makes possible use tidyselect inputs support duplicate names, like regular vectors.","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"other-features-and-fixes-1-0-0","dir":"Changelog","previous_headings":"","what":"Other features and fixes","title":"tidyselect 1.0.0","text":".strict argument vars_select() now works robustly consistently. Using arithmetic operators selection context now fails informatively (#84). now possible select columns data frames containing duplicate variables (#94). However, duplicates can’t part final selection. eval_rename() longer ignore names unquoted character vectors length 1 (#79). eval_rename() now fails variable renamed existing name (#70). eval_rename() better support existing duplicates (creating new duplicates error). eval_select(), eval_rename() vars_pull() now detect missing values uniformly (#72). vars_pull() now includes faulty expression error messages. performance issues eval_rename() many arguments fixed. make dplyr::rename_all() many columns much faster (@zkamvar, #92). tidyselect now much faster many columns, thanks performance fix rlang::env_bind() well internal fixes. vars_select() ignores vectors zeros (#82).","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"tidyselect-025","dir":"Changelog","previous_headings":"","what":"tidyselect 0.2.5","title":"tidyselect 0.2.5","text":"CRAN release: 2018-10-11 maintenance release compatibility rlang 0.3.0.","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"tidyselect-024","dir":"Changelog","previous_headings":"","what":"tidyselect 0.2.4","title":"tidyselect 0.2.4","text":"CRAN release: 2018-02-26 Fixed warning occurred vector column positions supplied vars_select() functions depending tidyr::gather() (#43 tidyverse/tidyr#374). Fixed compatibility issue rlang 0.2.0 (#51).","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"tidyselect-023","dir":"Changelog","previous_headings":"","what":"tidyselect 0.2.3","title":"tidyselect 0.2.3","text":"CRAN release: 2017-11-06 Internal fixes prevision using tidyselect within dplyr. vars_select() vars_rename() now correctly support unquoting character vectors names. vars_select() now ignores missing variables.","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"tidyselect-022","dir":"Changelog","previous_headings":"","what":"tidyselect 0.2.2","title":"tidyselect 0.2.2","text":"CRAN release: 2017-10-10 dplyr now correctly mentioned suggested package.","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"tidyselect-021","dir":"Changelog","previous_headings":"","what":"tidyselect 0.2.1","title":"tidyselect 0.2.1","text":"CRAN release: 2017-10-09 - now supports character vectors addition strings. makes easy unquote column names exclude set: {r} vars <- c(\"cyl\", \"\", \"disp\", \"drat\") vars_select(names(mtcars), - !!vars) last_col() now issues error variable vector empty. last_col() now returns column positions rather column names consistency helpers. also makes compatible functions like seq(). c() now supports character vectors way - seq(). (#37 @gergness)","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"tidyselect-020","dir":"Changelog","previous_headings":"","what":"tidyselect 0.2.0","title":"tidyselect 0.2.0","text":"CRAN release: 2017-08-30 main point release revert troublesome behaviour introduced tidyselect 0.1.0. also includes features.","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"evaluation-rules-0-2-0","dir":"Changelog","previous_headings":"","what":"Evaluation rules","title":"tidyselect 0.2.0","text":"special evaluation semantics selection changed back old behaviour new rules causing much trouble confusion. now data expressions (symbols calls : c()) can refer registered variables objects context. However semantics context expressions (calls : c()) remain . expressions evaluated context refer registered variables. ’re writing functions refer contextual objects, still good idea avoid data expressions. Since registered variables change function user input never know local objects might shadowed variable. Consider: select second element letters 14th? Since variables precedence data expression, select 14 first letters. can made robust turning data expression context expression: can also use quasiquotation since unquoted arguments guaranteed evaluated without user data scope. equivalent special rules context expressions, may clearer reader accustomed tidy eval: {r} vars_select(letters, seq(1, !! n)) Finally, may want explicit opposite direction. expect variable found data context, can use .data pronoun: {r} vars_select(names(mtcars), .data$cyl : .data$drat)","code":"n <- 2 vars_select(letters, 1:n) vars_select(letters, seq(1, n))"},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"new-features-0-2-0","dir":"Changelog","previous_headings":"","what":"New features","title":"tidyselect 0.2.0","text":"new select helper last_col() helpful select custom range: vars_select(vars, 3:last_col()). : - now handle strings well. makes easy unquote column name: (!!name) : last_col() - !!name. vars_select() gains .strict argument similar rename_vars(). set FALSE, errors unknown variables ignored. vars_select() now treats NULL empty inputs. follows trend tidyverse tools. vars_rename() now handles variable positions (integers round doubles) just like vars_select() (#20). vars_rename() now implemented tidy eval framework. Like vars_select(), expressions evaluated without user data scope. addition variable context now established can write rename helpers. return single round number string (variable position variable name). has_vars() predicate tests whether variable context set (#21). selection helpers now exported list vars_select_helpers. intended APIs embed helpers evaluation environment.","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"fixes-0-2-0","dir":"Changelog","previous_headings":"","what":"Fixes","title":"tidyselect 0.2.0","text":"one_of() argument vars renamed .vars avoid spurious matching.","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"tidyselect-011","dir":"Changelog","previous_headings":"","what":"tidyselect 0.1.1","title":"tidyselect 0.1.1","text":"CRAN release: 2017-07-24 tidyselect new home legacy functions dplyr::select_vars(), dplyr::rename_vars() dplyr::select_var().","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"api-changes-0-1-1","dir":"Changelog","previous_headings":"","what":"API changes","title":"tidyselect 0.1.1","text":"took opportunity make changes API: select_vars() rename_vars() now vars_select() vars_rename(). follows tidyverse convention prefix corresponds input type suffixes indicate output type. Similarly, select_var() now vars_pull(). arguments now prefixed dots limit argument matching issues. dots help, still good idea splice list captured quosures make sure dotted arguments never matched vars_select()’s named arguments: Error messages can now customised. consistency dplyr, error messages refer “columns” default. assumes variables selected come data frame. appropriate DSL, can now add attribute vars_type .vars vector specify alternative names. must character vector length 2 whose first component singular form second plural. example, c(\"variable\", \"variables\").","code":"vars_select(vars, !!! quos(...))"},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"establishing-a-variable-context-0-1-1","dir":"Changelog","previous_headings":"","what":"Establishing a variable context","title":"tidyselect 0.1.1","text":"tidyselect provides ways establishing variable context: scoped_vars() sets variable context along exit hook automatically restores previous variables. preferred way changing variable context. with_vars() takes variables expression evaluates latter context former. poke_vars() establishes new variable context. returns previous context invisibly responsibility restore done. expert use . current_vars() renamed peek_vars(). naming reference peek poke legacy languages.","code":""},{"path":"https://tidyselect.r-lib.org/dev/news/index.html","id":"new-evaluation-semantics-0-1-1","dir":"Changelog","previous_headings":"","what":"New evaluation semantics","title":"tidyselect 0.1.1","text":"evaluation semantics selecting verbs changed. Symbols now evaluated data-context isolated calling environment. means can longer refer local variables unless explicitly unquoting variables !!, mostly expert use. Note since dplyr 0.7, helper calls (like starts_with()) obey opposite behaviour evaluated calling context isolated data context. sum , symbols can refer data frame objects, helpers can refer contextual objects. differs usual R evaluation semantics data calling environment scope (former prevailing latter).","code":""}]