Skip to contents

Enhanced select() with data-masking

Usage

s_select(.data, ...)

Arguments

.data

A data frame, data frame extension (e.g. a tibble), or a lazy data frame (e.g. from dbplyr or dtplyr).

...

<tidy-select> or <data-masking> Variables to tabulate.

Both tidyselect (e.g., starts_with()) and data masking (e.g., x_sq = x^2) are supported. See examples below.

Value

A tibble

Examples

starwars %>%
  s_select()
#> # A tibble: 87 × 14
#>    name     height  mass hair_color skin_color eye_color birth_year sex   gender
#>    <chr>     <int> <dbl> <chr>      <chr>      <chr>          <dbl> <chr> <chr> 
#>  1 Luke Sk…    172    77 blond      fair       blue            19   male  mascu…
#>  2 C-3PO       167    75 NA         gold       yellow         112   none  mascu…
#>  3 R2-D2        96    32 NA         white, bl… red             33   none  mascu…
#>  4 Darth V…    202   136 none       white      yellow          41.9 male  mascu…
#>  5 Leia Or…    150    49 brown      light      brown           19   fema… femin…
#>  6 Owen La…    178   120 brown, gr… light      blue            52   male  mascu…
#>  7 Beru Wh…    165    75 brown      light      blue            47   fema… femin…
#>  8 R5-D4        97    32 NA         white, red red             NA   none  mascu…
#>  9 Biggs D…    183    84 black      light      brown           24   male  mascu…
#> 10 Obi-Wan…    182    77 auburn, w… fair       blue-gray       57   male  mascu…
#> # ℹ 77 more rows
#> # ℹ 5 more variables: homeworld <chr>, species <chr>, films <list>,
#> #   vehicles <list>, starships <list>
starwars %>%
  s_select(name, height)
#> # A tibble: 87 × 2
#>    name               height
#>    <chr>               <int>
#>  1 Luke Skywalker        172
#>  2 C-3PO                 167
#>  3 R2-D2                  96
#>  4 Darth Vader           202
#>  5 Leia Organa           150
#>  6 Owen Lars             178
#>  7 Beru Whitesun lars    165
#>  8 R5-D4                  97
#>  9 Biggs Darklighter     183
#> 10 Obi-Wan Kenobi        182
#> # ℹ 77 more rows
if (FALSE) {
starwars %>%
  dplyr::select(height > 50)
}
starwars %>%
  s_select(height > 50)
#> # A tibble: 87 × 1
#>    `height > 50`
#>    <lgl>        
#>  1 TRUE         
#>  2 TRUE         
#>  3 TRUE         
#>  4 TRUE         
#>  5 TRUE         
#>  6 TRUE         
#>  7 TRUE         
#>  8 TRUE         
#>  9 TRUE         
#> 10 TRUE         
#> # ℹ 77 more rows