exact_cols: List exact names of columns.

Description Usage Arguments Details Value Examples

Description

exact_cols returns the exact column names, including the case.

Usage

1
exact_cols(tbl, cols)

Arguments

tbl

A tibble or dataframe.

cols

A character vector of column names.

Details

This particularly useful when working with Microsoft SQL Server tables as the column names may be case sensitive. This is also useful when working with table metadata and the exact column names are required for matching purposes.

tbl_vars does not return case sensitive columns, thus the the need for this function.

Value

A character vector of column names with the appropriate case.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
## create tibble
my_tibble <- tibble::tribble(
  ~MixedCase, ~lowercase, ~UPPERCASE, ~aLtCaSe,
  1, 11, 111, 1111,
  2, 22, 222, 2222,
  3, 33, 333, 3333
)

## column names to search for, ignoring case
my_cols <- c("mixedcase", "altcase")

my_cols_case <- my_tibble %>%
  exact_cols(my_cols)

## particularly useful when combined with dplyr::one_of
my_tibble %>%
  dplyr::select(dplyr::one_of(my_cols_case))

curtisalexander/CRAmisc documentation built on May 14, 2019, 12:52 p.m.