dta_columns()
retrieves the names of specified columns from
a data frame or tibble.
Arguments
- dat
A data frame or tibble from which to select columns.
- .columns
Column name(s) to be selected from
dat
. Supports tidy selection syntax.- is_one_column
A logical value indicating whether only one column should be selected. If
TRUE
and more than one column is selected, an error is thrown. Default isFALSE
.
Examples
data(mtcars)
dta_gtable(head(mtcars))
dta_columns(mtcars, .columns = starts_with("c"))
#> [1] "cyl" "carb"
dta_columns(mtcars, .columns = cyl:wt)
#> [1] "cyl" "disp" "hp" "drat" "wt"
dta_columns(mtcars, .columns = c(mpg, hp, vs, gear))
#> [1] "mpg" "hp" "vs" "gear"
try(dta_columns(mtcars, .columns = c(mpg, hp, vs, gear), is_one_column = TRUE))
#> Error in dta_columns(mtcars, .columns = c(mpg, hp, vs, gear), is_one_column = TRUE) :
#> Expected 1 column but got 4 columns