-
Notifications
You must be signed in to change notification settings - Fork 0
/
mutate_all_.R
45 lines (40 loc) · 920 Bytes
/
mutate_all_.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#' @title
#' Mutate All Columns to Character
#'
#' @param data A dataframe or tibble.
#' @example inst/examples/mutate_all_.R
#' @seealso
#' \code{\link[dplyr]{mutate_all}}
#' @rdname mutate_all_char
#' @export
#' @importFrom dplyr mutate_all
mutate_all_char <-
function(data) {
data %>%
dplyr::mutate_all(as.character)
}
#' @title
#' Trim Whitespace of all Character Columns
#'
#' @param data A dataframe or tibble.
#' @inheritParams base::trimws
#'
#' @example inst/examples/mutate_all_.R
#' @seealso
#' \code{\link[dplyr]{mutate_at}}
#' @rdname mutate_all_trimws
#' @export
#' @importFrom dplyr mutate_at all_of
mutate_all_trimws <-
function(data,
which = c("both", "left", "right"),
whitespace = "[ \t\r\n]") {
data %>%
dplyr::mutate_if(
is.character,
~ trimws(.,
which = which,
whitespace = whitespace
)
)
}