Skip to contents

List column names by tidyselect

Usage

ds(.data, ...)

ds_as_column(.data, ...)

names_as_column(.data, ...)

Arguments

.data

A data frame

...

<tidy-select> Variables to select.

Value

A character vector of column names.

Examples

ds(starwars) # equivalent to names(starwars)
#>  [1] "name"       "height"     "mass"       "hair_color" "skin_color"
#>  [6] "eye_color"  "birth_year" "sex"        "gender"     "homeworld" 
#> [11] "species"    "films"      "vehicles"   "starships" 

ds(starwars, homeworld:starships)
#> [1] "homeworld" "species"   "films"     "vehicles"  "starships"

ds_as_column(starwars, ends_with("color"))
#> # A tibble: 3 × 1
#>   name      
#>   <chr>     
#> 1 hair_color
#> 2 skin_color
#> 3 eye_color 

ds_as_column(starwars, where(is.character))
#> # A tibble: 8 × 1
#>   name      
#>   <chr>     
#> 1 name      
#> 2 hair_color
#> 3 skin_color
#> 4 eye_color 
#> 5 sex       
#> 6 gender    
#> 7 homeworld 
#> 8 species   


names_as_column(starwars)
#> # A tibble: 14 × 1
#>    name      
#>    <chr>     
#>  1 name      
#>  2 height    
#>  3 mass      
#>  4 hair_color
#>  5 skin_color
#>  6 eye_color 
#>  7 birth_year
#>  8 sex       
#>  9 gender    
#> 10 homeworld 
#> 11 species   
#> 12 films     
#> 13 vehicles  
#> 14 starships 

names_as_column(starwars, ends_with("color"))
#> # A tibble: 3 × 1
#>   name      
#>   <chr>     
#> 1 hair_color
#> 2 skin_color
#> 3 eye_color 

names_as_column(starwars, where(is.character))
#> # A tibble: 8 × 1
#>   name      
#>   <chr>     
#> 1 name      
#> 2 hair_color
#> 3 skin_color
#> 4 eye_color 
#> 5 sex       
#> 6 gender    
#> 7 homeworld 
#> 8 species