Skip to contents

dta_columns() retrieves the names of specified columns from a data frame or tibble.

Usage

dta_columns(dat, .columns, is_one_column = FALSE)

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 is FALSE.

Value

A character vector containing the names of the selected columns.

Examples

data(mtcars)
dta_gtable(head(mtcars))
mpg cyl disp hp drat wt qsec vs am gear carb
21.0 6 160 110 3.90 2.620 16.46 0 1 4 4
21.0 6 160 110 3.90 2.875 17.02 0 1 4 4
22.8 4 108 93 3.85 2.320 18.61 1 1 4 1
21.4 6 258 110 3.08 3.215 19.44 1 0 3 1
18.7 8 360 175 3.15 3.440 17.02 0 0 3 2
18.1 6 225 105 2.76 3.460 20.22 1 0 3 1
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