cap_it: Cap It

Description Usage Arguments Examples

View source: R/cap_it.R

Description

Capitalize a vector or dataframe using one of the apply or purrr functions.

Usage

1
cap_it(e, ...)

Arguments

e

A vector or dataframe.

...

Other arguments

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
pre_cap_vec <- c("an all", "lowercase_string", "we.want", "to capitalize")
capped_vec <- pre_cap_vec %>% purrr::map_chr(cap_it)

pre_cap_df <- list("another all" = c("blah_blah", "blah"),
                   "lowercase.dataframe" = c(1, 4),
                   "to.cap" = c("BLAMO", "blam.o")) %>%
  tibble::as_tibble()


first_col <- pre_cap_df[[1]] %>% purrr::map_chr(cap_it)
second_col <- pre_cap_df[[2]] %>%
  purrr::map_chr(cap_it) # Numeric column coerced from numeric to character

# Capitalize all character elements of dataframe and column names
capped_df <- pre_cap_df
names(capped_df) <- names(pre_cap_df) %>% purrr::map(cap_it) %>%
    purrr::as_vector()
names(capped_df)

aedobbyn/dobtools documentation built on May 28, 2019, 2:33 a.m.