From 9c8fcc0d8e3f361109bbe61d082463a1e36972c5 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 24 Nov 2024 22:09:27 +0100 Subject: [PATCH 1/4] minor docs --- R/data_summary.R | 6 +++--- man/data_summary.Rd | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/R/data_summary.R b/R/data_summary.R index 7662d0c94..546c47659 100644 --- a/R/data_summary.R +++ b/R/data_summary.R @@ -5,9 +5,9 @@ #' data frame or a matrix. #' #' @param x A (grouped) data frame. -#' @param by Optional character string, indicating the name of a variable in `x`. -#' If supplied, the data will be split by this variable and summary statistics -#' will be computed for each group. +#' @param by Optional character string, indicating the names of one or more +#' variables in the data frame. If supplied, the data will be split by these +#' variables and summary statistics will be computed for each group. #' @param remove_na Logical. If `TRUE`, missing values are omitted from the #' grouping variable. If `FALSE` (default), missing values are included as a #' level in the grouping variable. diff --git a/man/data_summary.Rd b/man/data_summary.Rd index 24cfa1a9f..82d154175 100644 --- a/man/data_summary.Rd +++ b/man/data_summary.Rd @@ -18,9 +18,9 @@ and the function to compute the summary statistic. Example: as a character string, e.g. \code{"mean_sepal_width = mean(Sepal.Width)"}. The summary function \code{n()} can be used to count the number of observations.} -\item{by}{Optional character string, indicating the name of a variable in \code{x}. -If supplied, the data will be split by this variable and summary statistics -will be computed for each group.} +\item{by}{Optional character string, indicating the names of one or more +variables in the data frame. If supplied, the data will be split by these +variables and summary statistics will be computed for each group.} \item{remove_na}{Logical. If \code{TRUE}, missing values are omitted from the grouping variable. If \code{FALSE} (default), missing values are included as a From b727cb6a729dddd3c98a3949a25ac0f78aebc0fa Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 27 Nov 2024 15:52:10 +0100 Subject: [PATCH 2/4] Allow glue-styled pattern for `data_rename()` (#563) * Allow curl-styled pattern for `data_rename()` * add test * news * lintr * curl -> glue * allow alias * add options * typo * address comments * remove # in comment * fix --- DESCRIPTION | 2 +- NEWS.md | 7 +- R/data_rename.R | 158 ++++++++++++++++++++++++++---- man/categorize.Rd | 12 ++- man/data_match.Rd | 12 ++- man/data_merge.Rd | 12 ++- man/data_partition.Rd | 12 ++- man/data_relocate.Rd | 12 ++- man/data_rename.Rd | 77 ++++++++++++--- man/data_rotate.Rd | 12 ++- man/data_to_long.Rd | 12 ++- man/data_to_wide.Rd | 12 ++- man/extract_column_names.Rd | 12 ++- man/recode_values.Rd | 12 ++- man/slide.Rd | 12 ++- man/text_format.Rd | 19 ++-- man/winsorize.Rd | 12 ++- tests/testthat/test-data_rename.R | 86 ++++++++++++++++ 18 files changed, 401 insertions(+), 92 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 2325c062d..be41e0f6f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: datawizard Title: Easy Data Wrangling and Statistical Transformations -Version: 0.13.0.13 +Version: 0.13.0.14 Authors@R: c( person("Indrajeet", "Patil", , "patilindrajeet.science@gmail.com", role = "aut", comment = c(ORCID = "0000-0003-1995-6531")), diff --git a/NEWS.md b/NEWS.md index 663efa310..15b7f853d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -19,8 +19,11 @@ CHANGES * `data_read()` no longer shows warning about forthcoming breaking changes in upstream packages when reading `.RData` files. -* `data_modify()` now recognizes `n()`, for example to create an index for data groups - with `1:n()` (#535). +* `data_modify()` now recognizes `n()`, for example to create an index for data + groups with `1:n()` (#535). + +* The `replacement` argument in `data_rename()` now supports glue-styled + tokens (#563). BUG FIXES diff --git a/R/data_rename.R b/R/data_rename.R index 18f45657b..f5d6e0e03 100644 --- a/R/data_rename.R +++ b/R/data_rename.R @@ -10,18 +10,43 @@ #' pipe-workflow. #' #' @param data A data frame, or an object that can be coerced to a data frame. -#' @param pattern Character vector. For `data_rename()`, indicates columns that -#' should be selected for renaming. Can be `NULL` (in which case all columns -#' are selected). For `data_addprefix()` or `data_addsuffix()`, a character -#' string, which will be added as prefix or suffix to the column names. For -#' `data_rename()`, `pattern` can also be a named vector. In this case, names -#' are used as values for the `replacement` argument (i.e. `pattern` can be a -#' character vector using ` = ""` and argument `replacement` -#' will be ignored then). -#' @param replacement Character vector. Indicates the new name of the columns -#' selected in `pattern`. Can be `NULL` (in which case column are numbered -#' in sequential order). If not `NULL`, `pattern` and `replacement` must be -#' of the same length. If `pattern` is a named vector, `replacement` is ignored. +#' @param pattern Character vector. +#' - For `data_addprefix()` or `data_addsuffix()`, a character string, which +#' will be added as prefix or suffix to the column names. +#' - For `data_rename()`, indicates columns that should be selected for +#' renaming. Can be `NULL` (in which case all columns are selected). +#' `pattern` can also be a named vector. In this case, names are used as +#' values for the `replacement` argument (i.e. `pattern` can be a character +#' vector using ` = ""` and argument `replacement` will +#' be ignored then). +#' @param replacement Character vector. Can be one of the following: +#' - A character vector that indicates the new names of the columns selected +#' in `pattern`. `pattern` and `replacement` must be of the same length. +#' - `NULL`, in which case columns are numbered in sequential order. +#' - A string (i.e. character vector of length 1) with a "glue" styled pattern. +#' Currently supported tokens are: +#' - `{col}` which will be replaced by the column name, i.e. the +#' corresponding value in `pattern`. +#' - `{n}` will be replaced by the number of the variable that is replaced. +#' - `{letter}` will be replaced by alphabetical letters in sequential order. +#' If more than 26 letters are required, letters are repeated, but have +#' sequential numeric indices (e.g., `a1` to `z1`, followed by `a2` to `z2`). +#' - Finally, the name of a user-defined object that is available in the +#' environment can be used. Note that the object's name is not allowed to +#' be one of the pre-defined tokens, `"col"`, `"n"` and `"letter"`. +#' +#' An example for the use of tokens is... +#' ```r +#' data_rename( +#' mtcars, +#' pattern = c("am", "vs"), +#' replacement = "new_name_from_{col}" +#' ) +#' ``` +#' ... which would return new column names `new_name_from_am` and +#' `new_name_from_vs`. See 'Examples'. +#' +#' If `pattern` is a named vector, `replacement` is ignored. #' @param rows Vector of row names. #' @param safe Do not throw error if for instance the variable to be #' renamed/removed doesn't exist. @@ -45,13 +70,26 @@ #' #' # Change all #' head(data_rename(iris, replacement = paste0("Var", 1:5))) +#' +#' # Use glue-styled patterns +#' head(data_rename(mtcars[1:3], c("mpg", "cyl", "disp"), "formerly_{col}")) +#' head(data_rename(mtcars[1:3], c("mpg", "cyl", "disp"), "{col}_is_column_{n}")) +#' head(data_rename(mtcars[1:3], c("mpg", "cyl", "disp"), "new_{letter}")) +#' +#' # User-defined glue-styled patterns from objects in environment +#' x <- c("hi", "there", "!") +#' head(data_rename(mtcars[1:3], c("mpg", "cyl", "disp"), "col_{x}")) #' @seealso -#' - Functions to rename stuff: [data_rename()], [data_rename_rows()], [data_addprefix()], [data_addsuffix()] -#' - Functions to reorder or remove columns: [data_reorder()], [data_relocate()], [data_remove()] -#' - Functions to reshape, pivot or rotate data frames: [data_to_long()], [data_to_wide()], [data_rotate()] +#' - Functions to rename stuff: [data_rename()], [data_rename_rows()], +#' [data_addprefix()], [data_addsuffix()] +#' - Functions to reorder or remove columns: [data_reorder()], [data_relocate()], +#' [data_remove()] +#' - Functions to reshape, pivot or rotate data frames: [data_to_long()], +#' [data_to_wide()], [data_rotate()] #' - Functions to recode data: [rescale()], [reverse()], [categorize()], #' [recode_values()], [slide()] -#' - Functions to standardize, normalize, rank-transform: [center()], [standardize()], [normalize()], [ranktransform()], [winsorize()] +#' - Functions to standardize, normalize, rank-transform: [center()], [standardize()], +#' [normalize()], [ranktransform()], [winsorize()] #' - Split and merge data frames: [data_partition()], [data_merge()] #' - Functions to find or select columns: [data_select()], [extract_column_names()] #' - Functions to filter rows: [data_match()], [data_filter()] @@ -122,6 +160,9 @@ data_rename <- function(data, } } + # check if we have "glue" styled replacement-string + glue_style <- length(replacement) == 1 && grepl("{", replacement, fixed = TRUE) + if (length(replacement) > length(pattern) && verbose) { insight::format_alert( paste0( @@ -129,7 +170,7 @@ data_rename <- function(data, length(replacement) - length(pattern), " names of `replacement` are not used." ) ) - } else if (length(replacement) < length(pattern) && verbose) { + } else if (length(replacement) < length(pattern) && verbose && !glue_style) { insight::format_alert( paste0( "There are more names in `pattern` than in `replacement`. The last ", @@ -138,6 +179,11 @@ data_rename <- function(data, ) } + # if we have glue-styled replacement-string, create replacement pattern now + if (glue_style) { + replacement <- .glue_replacement(pattern, replacement) + } + for (i in seq_along(pattern)) { if (!is.na(replacement[i])) { data <- .data_rename(data, pattern[i], replacement[i], safe, verbose) @@ -167,6 +213,84 @@ data_rename <- function(data, } +.glue_replacement <- function(pattern, replacement) { + # this function replaces "glue" tokens into their related + # real names/values. Currently, following tokens are accepted: + # - {col}: replacement is the name of the column (indicated in "pattern") + # - {letter}: replacement is lower-case alphabetically letter, in sequential order + # - {n}: replacement is the number of the variable out of n, that should be renamed + out <- rep_len("", length(pattern)) + + # for alphabetical letters, we prepare a string if we have more than + # 26 columns to rename + if (length(out) > 26) { + long_letters <- paste0( + rep.int(letters[1:26], times = ceiling(length(out) / 26)), + rep(1:ceiling(length(out) / 26), each = 26) + ) + } else { + long_letters <- letters[1:26] + } + long_letters <- long_letters[seq_len(length(out))] + + for (i in seq_along(out)) { + # prepare pattern + column_name <- pattern[i] + out[i] <- replacement + # replace first pre-defined token + out[i] <- gsub( + "(.*)(\\{col\\})(.*)", + replacement = paste0("\\1", column_name, "\\3"), + x = out[i] + ) + # replace second pre-defined token + out[i] <- gsub( + "(.*)(\\{n\\})(.*)", + replacement = paste0("\\1", i, "\\3"), + x = out[i] + ) + # replace third pre-defined token + out[i] <- gsub( + "(.*)(\\{letter\\})(.*)", + replacement = paste0("\\1", long_letters[i], "\\3"), + x = out[i] + ) + # extract all non-standard tokens + matches <- unlist( + regmatches(out[i], gregexpr("\\{([^}]*)\\}", out[i])), + use.names = FALSE + ) + # do we have any additional tokens, i.e. variable names from the environment? + # users can also specify variable names, where the + if (length(matches)) { + # if so, iterate all tokens + for (token in matches) { + # evaluate token-object from the environment + values <- .dynEval( + str2lang(gsub("\\{(.*)\\}", "\\1", token)), + ifnotfound = insight::format_error(paste0( + "The object `", token, "` was not found. Please check if it really exists." + )) + ) + # check for correct length + if (length(values) != length(pattern)) { + insight::format_error(paste0( + "The number of values provided in `", token, "` (", length(values), + " values) do not match the number of columns to rename (", + length(pattern), " columns)." + )) + } + # replace token with values from the object + if (length(values)) { + out[i] <- gsub(token, values[i], out[i], fixed = TRUE) + } + } + } + } + out +} + + # Row.names ---------------------------------------------------------------- #' @rdname data_rename diff --git a/man/categorize.Rd b/man/categorize.Rd index dbecbf5e6..90a5e12b7 100644 --- a/man/categorize.Rd +++ b/man/categorize.Rd @@ -243,12 +243,16 @@ categorize(mtcars$mpg, "equal_length", n_groups = 5, labels = "observed") } \seealso{ \itemize{ -\item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, \code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} -\item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, \code{\link[=data_remove]{data_remove()}} -\item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, \code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} +\item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, +\code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} +\item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, +\code{\link[=data_remove]{data_remove()}} +\item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, +\code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} \item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=recode_values]{recode_values()}}, \code{\link[=slide]{slide()}} -\item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, \code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} +\item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, +\code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} \item Split and merge data frames: \code{\link[=data_partition]{data_partition()}}, \code{\link[=data_merge]{data_merge()}} \item Functions to find or select columns: \code{\link[=data_select]{data_select()}}, \code{\link[=extract_column_names]{extract_column_names()}} \item Functions to filter rows: \code{\link[=data_match]{data_match()}}, \code{\link[=data_filter]{data_filter()}} diff --git a/man/data_match.Rd b/man/data_match.Rd index a209170ab..0354a44f4 100644 --- a/man/data_match.Rd +++ b/man/data_match.Rd @@ -128,12 +128,16 @@ data_filter(mtcars, fl) } \seealso{ \itemize{ -\item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, \code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} -\item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, \code{\link[=data_remove]{data_remove()}} -\item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, \code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} +\item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, +\code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} +\item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, +\code{\link[=data_remove]{data_remove()}} +\item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, +\code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} \item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=recode_values]{recode_values()}}, \code{\link[=slide]{slide()}} -\item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, \code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} +\item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, +\code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} \item Split and merge data frames: \code{\link[=data_partition]{data_partition()}}, \code{\link[=data_merge]{data_merge()}} \item Functions to find or select columns: \code{\link[=data_select]{data_select()}}, \code{\link[=extract_column_names]{extract_column_names()}} \item Functions to filter rows: \code{\link[=data_match]{data_match()}}, \code{\link[=data_filter]{data_filter()}} diff --git a/man/data_merge.Rd b/man/data_merge.Rd index a780e76eb..169771b27 100644 --- a/man/data_merge.Rd +++ b/man/data_merge.Rd @@ -190,12 +190,16 @@ data_merge(list(x, y, z), join = "bind", by = "id", id = "source") } \seealso{ \itemize{ -\item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, \code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} -\item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, \code{\link[=data_remove]{data_remove()}} -\item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, \code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} +\item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, +\code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} +\item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, +\code{\link[=data_remove]{data_remove()}} +\item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, +\code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} \item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=recode_values]{recode_values()}}, \code{\link[=slide]{slide()}} -\item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, \code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} +\item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, +\code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} \item Split and merge data frames: \code{\link[=data_partition]{data_partition()}}, \code{\link[=data_merge]{data_merge()}} \item Functions to find or select columns: \code{\link[=data_select]{data_select()}}, \code{\link[=extract_column_names]{extract_column_names()}} \item Functions to filter rows: \code{\link[=data_match]{data_match()}}, \code{\link[=data_filter]{data_filter()}} diff --git a/man/data_partition.Rd b/man/data_partition.Rd index 1150b4f28..73eb28286 100644 --- a/man/data_partition.Rd +++ b/man/data_partition.Rd @@ -68,12 +68,16 @@ lapply(out, function(i) table(i$Species)) } \seealso{ \itemize{ -\item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, \code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} -\item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, \code{\link[=data_remove]{data_remove()}} -\item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, \code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} +\item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, +\code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} +\item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, +\code{\link[=data_remove]{data_remove()}} +\item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, +\code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} \item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=recode_values]{recode_values()}}, \code{\link[=slide]{slide()}} -\item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, \code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} +\item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, +\code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} \item Split and merge data frames: \code{\link[=data_partition]{data_partition()}}, \code{\link[=data_merge]{data_merge()}} \item Functions to find or select columns: \code{\link[=data_select]{data_select()}}, \code{\link[=extract_column_names]{extract_column_names()}} \item Functions to filter rows: \code{\link[=data_match]{data_match()}}, \code{\link[=data_filter]{data_filter()}} diff --git a/man/data_relocate.Rd b/man/data_relocate.Rd index 9949b5d27..8f360579d 100644 --- a/man/data_relocate.Rd +++ b/man/data_relocate.Rd @@ -134,12 +134,16 @@ head(data_remove(iris, starts_with("Sepal"))) } \seealso{ \itemize{ -\item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, \code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} -\item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, \code{\link[=data_remove]{data_remove()}} -\item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, \code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} +\item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, +\code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} +\item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, +\code{\link[=data_remove]{data_remove()}} +\item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, +\code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} \item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=recode_values]{recode_values()}}, \code{\link[=slide]{slide()}} -\item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, \code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} +\item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, +\code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} \item Split and merge data frames: \code{\link[=data_partition]{data_partition()}}, \code{\link[=data_merge]{data_merge()}} \item Functions to find or select columns: \code{\link[=data_select]{data_select()}}, \code{\link[=extract_column_names]{extract_column_names()}} \item Functions to filter rows: \code{\link[=data_match]{data_match()}}, \code{\link[=data_filter]{data_filter()}} diff --git a/man/data_rename.Rd b/man/data_rename.Rd index 2ff779c21..2859c04d7 100644 --- a/man/data_rename.Rd +++ b/man/data_rename.Rd @@ -43,14 +43,17 @@ data_rename_rows(data, rows = NULL) \arguments{ \item{data}{A data frame, or an object that can be coerced to a data frame.} -\item{pattern}{Character vector. For \code{data_rename()}, indicates columns that -should be selected for renaming. Can be \code{NULL} (in which case all columns -are selected). For \code{data_addprefix()} or \code{data_addsuffix()}, a character -string, which will be added as prefix or suffix to the column names. For -\code{data_rename()}, \code{pattern} can also be a named vector. In this case, names -are used as values for the \code{replacement} argument (i.e. \code{pattern} can be a -character vector using \verb{ = ""} and argument \code{replacement} -will be ignored then).} +\item{pattern}{Character vector. +\itemize{ +\item For \code{data_addprefix()} or \code{data_addsuffix()}, a character string, which +will be added as prefix or suffix to the column names. +\item For \code{data_rename()}, indicates columns that should be selected for +renaming. Can be \code{NULL} (in which case all columns are selected). +\code{pattern} can also be a named vector. In this case, names are used as +values for the \code{replacement} argument (i.e. \code{pattern} can be a character +vector using \verb{ = ""} and argument \code{replacement} will +be ignored then). +}} \item{select}{Variables that will be included when performing the required tasks. Can be either @@ -107,10 +110,39 @@ functions (see 'Details'), this argument may be used as workaround.} \item{...}{Other arguments passed to or from other functions.} -\item{replacement}{Character vector. Indicates the new name of the columns -selected in \code{pattern}. Can be \code{NULL} (in which case column are numbered -in sequential order). If not \code{NULL}, \code{pattern} and \code{replacement} must be -of the same length. If \code{pattern} is a named vector, \code{replacement} is ignored.} +\item{replacement}{Character vector. Can be one of the following: +\itemize{ +\item A character vector that indicates the new names of the columns selected +in \code{pattern}. \code{pattern} and \code{replacement} must be of the same length. +\item \code{NULL}, in which case columns are numbered in sequential order. +\item A string (i.e. character vector of length 1) with a "glue" styled pattern. +Currently supported tokens are: +\itemize{ +\item \code{{col}} which will be replaced by the column name, i.e. the +corresponding value in \code{pattern}. +\item \code{{n}} will be replaced by the number of the variable that is replaced. +\item \code{{letter}} will be replaced by alphabetical letters in sequential order. +If more than 26 letters are required, letters are repeated, but have +sequential numeric indices (e.g., \code{a1} to \code{z1}, followed by \code{a2} to \code{z2}). +\item Finally, the name of a user-defined object that is available in the +environment can be used. Note that the object's name is not allowed to +be one of the pre-defined tokens, \code{"col"}, \code{"n"} and \code{"letter"}. +} + +An example for the use of tokens is... + +\if{html}{\out{
}}\preformatted{data_rename( + mtcars, + pattern = c("am", "vs"), + replacement = "new_name_from_\{col\}" +) +}\if{html}{\out{
}} + +... which would return new column names \code{new_name_from_am} and +\code{new_name_from_vs}. See 'Examples'. +} + +If \code{pattern} is a named vector, \code{replacement} is ignored.} \item{safe}{Do not throw error if for instance the variable to be renamed/removed doesn't exist.} @@ -148,15 +180,28 @@ head(data_rename(iris, NULL)) # Change all head(data_rename(iris, replacement = paste0("Var", 1:5))) + +# Use glue-styled patterns +head(data_rename(mtcars[1:3], c("mpg", "cyl", "disp"), "formerly_{col}")) +head(data_rename(mtcars[1:3], c("mpg", "cyl", "disp"), "{col}_is_column_{n}")) +head(data_rename(mtcars[1:3], c("mpg", "cyl", "disp"), "new_{letter}")) + +# User-defined glue-styled patterns from objects in environment +x <- c("hi", "there", "!") +head(data_rename(mtcars[1:3], c("mpg", "cyl", "disp"), "col_{x}")) } \seealso{ \itemize{ -\item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, \code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} -\item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, \code{\link[=data_remove]{data_remove()}} -\item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, \code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} +\item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, +\code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} +\item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, +\code{\link[=data_remove]{data_remove()}} +\item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, +\code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} \item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=recode_values]{recode_values()}}, \code{\link[=slide]{slide()}} -\item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, \code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} +\item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, +\code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} \item Split and merge data frames: \code{\link[=data_partition]{data_partition()}}, \code{\link[=data_merge]{data_merge()}} \item Functions to find or select columns: \code{\link[=data_select]{data_select()}}, \code{\link[=extract_column_names]{extract_column_names()}} \item Functions to filter rows: \code{\link[=data_match]{data_match()}}, \code{\link[=data_filter]{data_filter()}} diff --git a/man/data_rotate.Rd b/man/data_rotate.Rd index 604f4f603..25ba9a82b 100644 --- a/man/data_rotate.Rd +++ b/man/data_rotate.Rd @@ -52,12 +52,16 @@ data_rotate(x, colnames = "c") } \seealso{ \itemize{ -\item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, \code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} -\item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, \code{\link[=data_remove]{data_remove()}} -\item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, \code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} +\item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, +\code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} +\item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, +\code{\link[=data_remove]{data_remove()}} +\item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, +\code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} \item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=recode_values]{recode_values()}}, \code{\link[=slide]{slide()}} -\item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, \code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} +\item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, +\code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} \item Split and merge data frames: \code{\link[=data_partition]{data_partition()}}, \code{\link[=data_merge]{data_merge()}} \item Functions to find or select columns: \code{\link[=data_select]{data_select()}}, \code{\link[=extract_column_names]{extract_column_names()}} \item Functions to filter rows: \code{\link[=data_match]{data_match()}}, \code{\link[=data_filter]{data_filter()}} diff --git a/man/data_to_long.Rd b/man/data_to_long.Rd index 73b54219b..1c77f764c 100644 --- a/man/data_to_long.Rd +++ b/man/data_to_long.Rd @@ -222,12 +222,16 @@ head(even_longer_data) } \seealso{ \itemize{ -\item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, \code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} -\item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, \code{\link[=data_remove]{data_remove()}} -\item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, \code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} +\item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, +\code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} +\item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, +\code{\link[=data_remove]{data_remove()}} +\item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, +\code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} \item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=recode_values]{recode_values()}}, \code{\link[=slide]{slide()}} -\item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, \code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} +\item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, +\code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} \item Split and merge data frames: \code{\link[=data_partition]{data_partition()}}, \code{\link[=data_merge]{data_merge()}} \item Functions to find or select columns: \code{\link[=data_select]{data_select()}}, \code{\link[=extract_column_names]{extract_column_names()}} \item Functions to filter rows: \code{\link[=data_match]{data_match()}}, \code{\link[=data_filter]{data_filter()}} diff --git a/man/data_to_wide.Rd b/man/data_to_wide.Rd index 8b781fc76..3690eed53 100644 --- a/man/data_to_wide.Rd +++ b/man/data_to_wide.Rd @@ -208,12 +208,16 @@ data_to_wide( } \seealso{ \itemize{ -\item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, \code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} -\item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, \code{\link[=data_remove]{data_remove()}} -\item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, \code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} +\item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, +\code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} +\item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, +\code{\link[=data_remove]{data_remove()}} +\item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, +\code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} \item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=recode_values]{recode_values()}}, \code{\link[=slide]{slide()}} -\item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, \code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} +\item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, +\code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} \item Split and merge data frames: \code{\link[=data_partition]{data_partition()}}, \code{\link[=data_merge]{data_merge()}} \item Functions to find or select columns: \code{\link[=data_select]{data_select()}}, \code{\link[=extract_column_names]{extract_column_names()}} \item Functions to filter rows: \code{\link[=data_match]{data_match()}}, \code{\link[=data_filter]{data_filter()}} diff --git a/man/extract_column_names.Rd b/man/extract_column_names.Rd index 3ea5da7dc..bb0f9ada8 100644 --- a/man/extract_column_names.Rd +++ b/man/extract_column_names.Rd @@ -175,12 +175,16 @@ head(data_select(mtcars, c(`Miles per Gallon` = "mpg", Cylinders = "cyl"))) } \seealso{ \itemize{ -\item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, \code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} -\item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, \code{\link[=data_remove]{data_remove()}} -\item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, \code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} +\item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, +\code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} +\item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, +\code{\link[=data_remove]{data_remove()}} +\item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, +\code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} \item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=recode_values]{recode_values()}}, \code{\link[=slide]{slide()}} -\item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, \code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} +\item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, +\code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} \item Split and merge data frames: \code{\link[=data_partition]{data_partition()}}, \code{\link[=data_merge]{data_merge()}} \item Functions to find or select columns: \code{\link[=data_select]{data_select()}}, \code{\link[=extract_column_names]{extract_column_names()}} \item Functions to filter rows: \code{\link[=data_match]{data_match()}}, \code{\link[=data_filter]{data_filter()}} diff --git a/man/recode_values.Rd b/man/recode_values.Rd index dece902f7..66b7c6e32 100644 --- a/man/recode_values.Rd +++ b/man/recode_values.Rd @@ -278,12 +278,16 @@ options(data_recode_pattern = NULL) } \seealso{ \itemize{ -\item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, \code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} -\item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, \code{\link[=data_remove]{data_remove()}} -\item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, \code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} +\item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, +\code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} +\item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, +\code{\link[=data_remove]{data_remove()}} +\item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, +\code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} \item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=recode_values]{recode_values()}}, \code{\link[=slide]{slide()}} -\item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, \code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} +\item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, +\code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} \item Split and merge data frames: \code{\link[=data_partition]{data_partition()}}, \code{\link[=data_merge]{data_merge()}} \item Functions to find or select columns: \code{\link[=data_select]{data_select()}}, \code{\link[=extract_column_names]{extract_column_names()}} \item Functions to filter rows: \code{\link[=data_match]{data_match()}}, \code{\link[=data_filter]{data_filter()}} diff --git a/man/slide.Rd b/man/slide.Rd index c26943116..2950855f4 100644 --- a/man/slide.Rd +++ b/man/slide.Rd @@ -123,12 +123,16 @@ sapply(mtcars, min) } \seealso{ \itemize{ -\item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, \code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} -\item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, \code{\link[=data_remove]{data_remove()}} -\item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, \code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} +\item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, +\code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} +\item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, +\code{\link[=data_remove]{data_remove()}} +\item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, +\code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} \item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=recode_values]{recode_values()}}, \code{\link[=slide]{slide()}} -\item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, \code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} +\item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, +\code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} \item Split and merge data frames: \code{\link[=data_partition]{data_partition()}}, \code{\link[=data_merge]{data_merge()}} \item Functions to find or select columns: \code{\link[=data_select]{data_select()}}, \code{\link[=extract_column_names]{extract_column_names()}} \item Functions to filter rows: \code{\link[=data_match]{data_match()}}, \code{\link[=data_filter]{data_filter()}} diff --git a/man/text_format.Rd b/man/text_format.Rd index 14d64b096..16c76e67c 100644 --- a/man/text_format.Rd +++ b/man/text_format.Rd @@ -50,14 +50,17 @@ text elements will not be enclosed.} \item{n}{The number of characters to find.} -\item{pattern}{Character vector. For \code{data_rename()}, indicates columns that -should be selected for renaming. Can be \code{NULL} (in which case all columns -are selected). For \code{data_addprefix()} or \code{data_addsuffix()}, a character -string, which will be added as prefix or suffix to the column names. For -\code{data_rename()}, \code{pattern} can also be a named vector. In this case, names -are used as values for the \code{replacement} argument (i.e. \code{pattern} can be a -character vector using \verb{ = ""} and argument \code{replacement} -will be ignored then).} +\item{pattern}{Character vector. +\itemize{ +\item For \code{data_addprefix()} or \code{data_addsuffix()}, a character string, which +will be added as prefix or suffix to the column names. +\item For \code{data_rename()}, indicates columns that should be selected for +renaming. Can be \code{NULL} (in which case all columns are selected). +\code{pattern} can also be a named vector. In this case, names are used as +values for the \code{replacement} argument (i.e. \code{pattern} can be a character +vector using \verb{ = ""} and argument \code{replacement} will +be ignored then). +}} } \value{ A character string. diff --git a/man/winsorize.Rd b/man/winsorize.Rd index 3971a1ae7..15fa6af9b 100644 --- a/man/winsorize.Rd +++ b/man/winsorize.Rd @@ -82,12 +82,16 @@ winsorize(iris, threshold = 0.2) } \seealso{ \itemize{ -\item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, \code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} -\item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, \code{\link[=data_remove]{data_remove()}} -\item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, \code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} +\item Functions to rename stuff: \code{\link[=data_rename]{data_rename()}}, \code{\link[=data_rename_rows]{data_rename_rows()}}, +\code{\link[=data_addprefix]{data_addprefix()}}, \code{\link[=data_addsuffix]{data_addsuffix()}} +\item Functions to reorder or remove columns: \code{\link[=data_reorder]{data_reorder()}}, \code{\link[=data_relocate]{data_relocate()}}, +\code{\link[=data_remove]{data_remove()}} +\item Functions to reshape, pivot or rotate data frames: \code{\link[=data_to_long]{data_to_long()}}, +\code{\link[=data_to_wide]{data_to_wide()}}, \code{\link[=data_rotate]{data_rotate()}} \item Functions to recode data: \code{\link[=rescale]{rescale()}}, \code{\link[=reverse]{reverse()}}, \code{\link[=categorize]{categorize()}}, \code{\link[=recode_values]{recode_values()}}, \code{\link[=slide]{slide()}} -\item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, \code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} +\item Functions to standardize, normalize, rank-transform: \code{\link[=center]{center()}}, \code{\link[=standardize]{standardize()}}, +\code{\link[=normalize]{normalize()}}, \code{\link[=ranktransform]{ranktransform()}}, \code{\link[=winsorize]{winsorize()}} \item Split and merge data frames: \code{\link[=data_partition]{data_partition()}}, \code{\link[=data_merge]{data_merge()}} \item Functions to find or select columns: \code{\link[=data_select]{data_select()}}, \code{\link[=extract_column_names]{extract_column_names()}} \item Functions to filter rows: \code{\link[=data_match]{data_match()}}, \code{\link[=data_filter]{data_filter()}} diff --git a/tests/testthat/test-data_rename.R b/tests/testthat/test-data_rename.R index e01c42f8b..79f4427b3 100644 --- a/tests/testthat/test-data_rename.R +++ b/tests/testthat/test-data_rename.R @@ -140,3 +140,89 @@ test_that("data_rename preserves attributes", { expect_named(a1, names(a2)) }) + + +# glue-styled pattern -------------------------- + +test_that("data_rename glue-style", { + data(mtcars) + out <- data_rename(mtcars[1:3], c("mpg", "cyl", "disp"), "formerly_{col}") + expect_named(out, c("formerly_mpg", "formerly_cyl", "formerly_disp")) + out <- data_rename(mtcars[1:3], c("mpg", "cyl", "disp"), "{col}_is_column_{n}") + expect_named(out, c("mpg_is_column_1", "cyl_is_column_2", "disp_is_column_3")) + out <- data_rename(mtcars[1:3], c("mpg", "cyl", "disp"), "new_{letter}") + expect_named(out, c("new_a", "new_b", "new_c")) +}) + +test_that("data_rename enough letters", { + data(efc, package = "datawizard") + data(mtcars) + data(iris) + data(ChickWeight) + data(ToothGrowth) + data(USArrests) + data(airquality) + x <- cbind( + mtcars[1:5, ], iris[1:5, ], efc[1:5, ], ChickWeight[1:5, ], ToothGrowth[1:5, ], + USArrests[1:5, ], airquality[1:5, ] + ) + expect_named( + data_rename(x, replacement = "long_letter_{letter}"), + c( + "long_letter_a1", "long_letter_b1", "long_letter_c1", "long_letter_d1", + "long_letter_e1", "long_letter_f1", "long_letter_g1", "long_letter_h1", + "long_letter_i1", "long_letter_j1", "long_letter_k1", "long_letter_l1", + "long_letter_m1", "long_letter_n1", "long_letter_o1", "long_letter_p1", + "long_letter_q1", "long_letter_r1", "long_letter_s1", "long_letter_t1", + "long_letter_u1", "long_letter_v1", "long_letter_w1", "long_letter_x1", + "long_letter_y1", "long_letter_z1", "long_letter_a2", "long_letter_b2", + "long_letter_c2", "long_letter_d2", "long_letter_e2", "long_letter_f2", + "long_letter_g2", "long_letter_h2", "long_letter_i2", "long_letter_j2", + "long_letter_k2", "long_letter_l2" + ) + ) +}) + +skip_if_not_installed("withr") +withr::with_environment( + new.env(), + test_that("data_rename glue-style, environment", { + data(mtcars) + x <- c("hi", "there", "!") + out <- data_rename(mtcars[1:3], c("mpg", "cyl", "disp"), "col_{x}") + expect_named(out, c("col_hi", "col_there", "col_!")) + expect_error( + data_rename(mtcars[1:3], c("mpg", "disp"), "col_{x}"), + regex = "The number of values" + ) + }) +) + +withr::with_environment( + new.env(), + test_that("data_rename glue-style, object not in environment", { + data(mtcars) + expect_error( + data_rename(mtcars[1:3], c("mpg", "cyl", "disp"), "col_{x}"), + regex = "The object" + ) + }) +) + +withr::with_environment( + new.env(), + test_that("data_rename glue-style, function in environment", { + data(mtcars) + my_fun <- function(cols_to_rename) { + data_rename(head(mtcars)[, 1:6], cols_to_rename, "new_{col}") + } + expect_named( + my_fun(c("mpg", "drat")), + c("new_mpg", "cyl", "disp", "hp", "new_drat", "wt") + ) + expect_named( + my_fun("mpg"), + c("new_mpg", "cyl", "disp", "hp", "drat", "wt") + ) + }) +) From 978cde7652ae57a4863e2f000a6b948a44889b6f Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 27 Nov 2024 17:41:30 +0100 Subject: [PATCH 3/4] Fix inconsitencies in docs (#565) * Fix inconsitencies in docs * Update R/extract_column_names.R Co-authored-by: Etienne Bacher <52219252+etiennebacher@users.noreply.github.com> * update rd (comma) --------- Co-authored-by: Etienne Bacher <52219252+etiennebacher@users.noreply.github.com> --- R/extract_column_names.R | 16 ++++++++++------ man/adjust.Rd | 11 ++++++----- man/assign_labels.Rd | 11 ++++++----- man/categorize.Rd | 11 ++++++----- man/center.Rd | 11 ++++++----- man/convert_na_to.Rd | 11 ++++++----- man/convert_to_na.Rd | 11 ++++++----- man/data_codebook.Rd | 11 ++++++----- man/data_duplicated.Rd | 11 ++++++----- man/data_extract.Rd | 11 ++++++----- man/data_group.Rd | 11 ++++++----- man/data_peek.Rd | 11 ++++++----- man/data_relocate.Rd | 11 ++++++----- man/data_rename.Rd | 11 ++++++----- man/data_replicate.Rd | 11 ++++++----- man/data_separate.Rd | 11 ++++++----- man/data_tabulate.Rd | 11 ++++++----- man/data_to_long.Rd | 11 ++++++----- man/data_unique.Rd | 11 ++++++----- man/data_unite.Rd | 11 ++++++----- man/describe_distribution.Rd | 11 ++++++----- man/extract_column_names.Rd | 16 ++++++++++------ man/labels_to_levels.Rd | 11 ++++++----- man/means_by_group.Rd | 11 ++++++----- man/normalize.Rd | 11 ++++++----- man/ranktransform.Rd | 11 ++++++----- man/recode_values.Rd | 11 ++++++----- man/rescale.Rd | 11 ++++++----- man/reverse.Rd | 11 ++++++----- man/row_count.Rd | 11 ++++++----- man/row_means.Rd | 11 ++++++----- man/slide.Rd | 11 ++++++----- man/standardize.Rd | 11 ++++++----- man/to_factor.Rd | 11 ++++++----- man/to_numeric.Rd | 11 ++++++----- 35 files changed, 218 insertions(+), 177 deletions(-) diff --git a/R/extract_column_names.R b/R/extract_column_names.R index a3d120d3f..b1cb54f35 100644 --- a/R/extract_column_names.R +++ b/R/extract_column_names.R @@ -19,15 +19,16 @@ #' - a vector of negative integers, giving the positions counting from the #' right (e.g., `-1` or `-1:-3`), #' - one of the following select-helpers: `starts_with()`, `ends_with()`, -#' `contains()`, a range using `:` or `regex("")`. `starts_with()`, +#' `contains()`, a range using `:`, or `regex()`. `starts_with()`, #' `ends_with()`, and `contains()` accept several patterns, e.g -#' `starts_with("Sep", "Petal")`. -#' - or a function testing for logical conditions, e.g. `is.numeric()` (or +#' `starts_with("Sep", "Petal")`. `regex()` can be used to define regular +#' expression patterns. +#' - a function testing for logical conditions, e.g. `is.numeric()` (or #' `is.numeric`), or any user-defined function that selects the variables #' for which the function returns `TRUE` (like: `foo <- function(x) mean(x) > 3`), #' - ranges specified via literal variable names, select-helpers (except #' `regex()`) and (user-defined) functions can be negated, i.e. return -#' non-matching elements, when prefixed with a `-`, e.g. `-ends_with("")`, +#' non-matching elements, when prefixed with a `-`, e.g. `-ends_with()`, #' `-is.numeric` or `-(Sepal.Width:Petal.Length)`. **Note:** Negation means #' that matches are _excluded_, and thus, the `exclude` argument can be #' used alternatively. For instance, `select=-ends_with("Length")` (with @@ -48,7 +49,7 @@ #' character string (or a variable containing a character string) and is not #' allowed to be one of the supported select-helpers or a character vector #' of length > 1. `regex = TRUE` is comparable to using one of the two -#' select-helpers, `select = contains("")` or `select = regex("")`, however, +#' select-helpers, `select = contains()` or `select = regex()`, however, #' since the select-helpers may not work when called from inside other #' functions (see 'Details'), this argument may be used as workaround. #' @param verbose Toggle warnings. @@ -131,7 +132,10 @@ #' numeric_mean_35 <- function(x) is.numeric(x) && mean(x, na.rm = TRUE) > 3.5 #' extract_column_names(iris, numeric_mean_35) #' -#' # find range of colum names by range, using character vector +#' # find column names, using range +#' extract_column_names(mtcars, c(cyl:hp, wt)) +#' +#' # find range of column names by range, using character vector #' extract_column_names(mtcars, c("cyl:hp", "wt")) #' #' # rename returned columns for "data_select()" diff --git a/man/adjust.Rd b/man/adjust.Rd index 48b321b8f..c47606ce0 100644 --- a/man/adjust.Rd +++ b/man/adjust.Rd @@ -53,15 +53,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -102,7 +103,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} diff --git a/man/assign_labels.Rd b/man/assign_labels.Rd index e6fd24252..574730e7b 100644 --- a/man/assign_labels.Rd +++ b/man/assign_labels.Rd @@ -48,15 +48,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -81,7 +82,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} diff --git a/man/categorize.Rd b/man/categorize.Rd index 90a5e12b7..0fed929de 100644 --- a/man/categorize.Rd +++ b/man/categorize.Rd @@ -99,15 +99,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -142,7 +143,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} } diff --git a/man/center.Rd b/man/center.Rd index 4774020ab..691f10839 100644 --- a/man/center.Rd +++ b/man/center.Rd @@ -82,15 +82,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -133,7 +134,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} } diff --git a/man/convert_na_to.Rd b/man/convert_na_to.Rd index 702e0eb2e..369e3937d 100644 --- a/man/convert_na_to.Rd +++ b/man/convert_na_to.Rd @@ -51,15 +51,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -90,7 +91,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} } diff --git a/man/convert_to_na.Rd b/man/convert_to_na.Rd index fe308d61e..f56fdd7da 100644 --- a/man/convert_to_na.Rd +++ b/man/convert_to_na.Rd @@ -54,15 +54,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -87,7 +88,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} } diff --git a/man/data_codebook.Rd b/man/data_codebook.Rd index d5a542be4..4fcddc1ff 100644 --- a/man/data_codebook.Rd +++ b/man/data_codebook.Rd @@ -44,15 +44,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -94,7 +95,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} diff --git a/man/data_duplicated.Rd b/man/data_duplicated.Rd index 88624c8c8..30d8a455d 100644 --- a/man/data_duplicated.Rd +++ b/man/data_duplicated.Rd @@ -30,15 +30,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -63,7 +64,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} diff --git a/man/data_extract.Rd b/man/data_extract.Rd index 0b544e710..91b5ee29a 100644 --- a/man/data_extract.Rd +++ b/man/data_extract.Rd @@ -37,15 +37,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -88,7 +89,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} diff --git a/man/data_group.Rd b/man/data_group.Rd index 9cb55de5d..c360f7b5e 100644 --- a/man/data_group.Rd +++ b/man/data_group.Rd @@ -34,15 +34,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -67,7 +68,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} diff --git a/man/data_peek.Rd b/man/data_peek.Rd index 9524c70ec..5d5e2e18e 100644 --- a/man/data_peek.Rd +++ b/man/data_peek.Rd @@ -37,15 +37,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -70,7 +71,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} diff --git a/man/data_relocate.Rd b/man/data_relocate.Rd index 8f360579d..5991691cb 100644 --- a/man/data_relocate.Rd +++ b/man/data_relocate.Rd @@ -54,15 +54,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -89,7 +90,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} diff --git a/man/data_rename.Rd b/man/data_rename.Rd index 2859c04d7..3fea0fac4 100644 --- a/man/data_rename.Rd +++ b/man/data_rename.Rd @@ -69,15 +69,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -102,7 +103,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} diff --git a/man/data_replicate.Rd b/man/data_replicate.Rd index 5a427d570..0be353c66 100644 --- a/man/data_replicate.Rd +++ b/man/data_replicate.Rd @@ -37,15 +37,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -76,7 +77,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} diff --git a/man/data_separate.Rd b/man/data_separate.Rd index 7c951f81c..b85b01916 100644 --- a/man/data_separate.Rd +++ b/man/data_separate.Rd @@ -40,15 +40,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -120,7 +121,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} diff --git a/man/data_tabulate.Rd b/man/data_tabulate.Rd index b28a26ede..ac91ead65 100644 --- a/man/data_tabulate.Rd +++ b/man/data_tabulate.Rd @@ -89,15 +89,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -122,7 +123,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} diff --git a/man/data_to_long.Rd b/man/data_to_long.Rd index 1c77f764c..3e587c049 100644 --- a/man/data_to_long.Rd +++ b/man/data_to_long.Rd @@ -55,15 +55,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -109,7 +110,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} diff --git a/man/data_unique.Rd b/man/data_unique.Rd index a0a70b92a..e0911901d 100644 --- a/man/data_unique.Rd +++ b/man/data_unique.Rd @@ -31,15 +31,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -67,7 +68,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} diff --git a/man/data_unite.Rd b/man/data_unite.Rd index 369fd33d8..c9893933e 100644 --- a/man/data_unite.Rd +++ b/man/data_unite.Rd @@ -37,15 +37,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -82,7 +83,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} diff --git a/man/describe_distribution.Rd b/man/describe_distribution.Rd index 80b69e115..4837834ac 100644 --- a/man/describe_distribution.Rd +++ b/man/describe_distribution.Rd @@ -96,15 +96,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -133,7 +134,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} } diff --git a/man/extract_column_names.Rd b/man/extract_column_names.Rd index bb0f9ada8..fe334e22f 100644 --- a/man/extract_column_names.Rd +++ b/man/extract_column_names.Rd @@ -53,15 +53,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -86,7 +87,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} @@ -167,7 +168,10 @@ extract_column_names(iris, starts_with("Sepal"), exclude = contains("Width")) numeric_mean_35 <- function(x) is.numeric(x) && mean(x, na.rm = TRUE) > 3.5 extract_column_names(iris, numeric_mean_35) -# find range of colum names by range, using character vector +# find column names, using range +extract_column_names(mtcars, c(cyl:hp, wt)) + +# find range of column names by range, using character vector extract_column_names(mtcars, c("cyl:hp", "wt")) # rename returned columns for "data_select()" diff --git a/man/labels_to_levels.Rd b/man/labels_to_levels.Rd index 163eb0eaa..c75e2f537 100644 --- a/man/labels_to_levels.Rd +++ b/man/labels_to_levels.Rd @@ -43,15 +43,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -86,7 +87,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} } diff --git a/man/means_by_group.Rd b/man/means_by_group.Rd index 6c06ac3b1..8407263b7 100644 --- a/man/means_by_group.Rd +++ b/man/means_by_group.Rd @@ -61,15 +61,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -94,7 +95,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} diff --git a/man/normalize.Rd b/man/normalize.Rd index c325e98fe..ecb3a2706 100644 --- a/man/normalize.Rd +++ b/man/normalize.Rd @@ -81,15 +81,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -121,7 +122,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} } diff --git a/man/ranktransform.Rd b/man/ranktransform.Rd index 7046db2b5..44b0052c4 100644 --- a/man/ranktransform.Rd +++ b/man/ranktransform.Rd @@ -49,15 +49,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -82,7 +83,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} } diff --git a/man/recode_values.Rd b/man/recode_values.Rd index 66b7c6e32..11f9cfadc 100644 --- a/man/recode_values.Rd +++ b/man/recode_values.Rd @@ -70,15 +70,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -113,7 +114,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} } diff --git a/man/rescale.Rd b/man/rescale.Rd index 490964777..8d6025a8d 100644 --- a/man/rescale.Rd +++ b/man/rescale.Rd @@ -77,15 +77,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -120,7 +121,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} } diff --git a/man/reverse.Rd b/man/reverse.Rd index 5767908ff..0f33154a4 100644 --- a/man/reverse.Rd +++ b/man/reverse.Rd @@ -55,15 +55,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -98,7 +99,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} } diff --git a/man/row_count.Rd b/man/row_count.Rd index 7bf54fe5f..1a87de609 100644 --- a/man/row_count.Rd +++ b/man/row_count.Rd @@ -33,15 +33,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -76,7 +77,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} diff --git a/man/row_means.Rd b/man/row_means.Rd index 43d85b5b0..3c859e992 100644 --- a/man/row_means.Rd +++ b/man/row_means.Rd @@ -47,15 +47,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -95,7 +96,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} diff --git a/man/slide.Rd b/man/slide.Rd index 2950855f4..d68f7e30a 100644 --- a/man/slide.Rd +++ b/man/slide.Rd @@ -44,15 +44,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -87,7 +88,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} diff --git a/man/standardize.Rd b/man/standardize.Rd index fcc8c6ae7..8e8d66867 100644 --- a/man/standardize.Rd +++ b/man/standardize.Rd @@ -155,15 +155,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -201,7 +202,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} } diff --git a/man/to_factor.Rd b/man/to_factor.Rd index d544bdaae..7a500c071 100644 --- a/man/to_factor.Rd +++ b/man/to_factor.Rd @@ -46,15 +46,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -89,7 +90,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} } diff --git a/man/to_numeric.Rd b/man/to_numeric.Rd index 39f04c3a9..abfcec0d8 100644 --- a/man/to_numeric.Rd +++ b/man/to_numeric.Rd @@ -40,15 +40,16 @@ character vector of variable names including ranges specified via \code{:} \item a vector of negative integers, giving the positions counting from the right (e.g., \code{-1} or \code{-1:-3}), \item one of the following select-helpers: \code{starts_with()}, \code{ends_with()}, -\code{contains()}, a range using \code{:} or \code{regex("")}. \code{starts_with()}, +\code{contains()}, a range using \code{:}, or \code{regex()}. \code{starts_with()}, \code{ends_with()}, and \code{contains()} accept several patterns, e.g -\code{starts_with("Sep", "Petal")}. -\item or a function testing for logical conditions, e.g. \code{is.numeric()} (or +\code{starts_with("Sep", "Petal")}. \code{regex()} can be used to define regular +expression patterns. +\item a function testing for logical conditions, e.g. \code{is.numeric()} (or \code{is.numeric}), or any user-defined function that selects the variables for which the function returns \code{TRUE} (like: \code{foo <- function(x) mean(x) > 3}), \item ranges specified via literal variable names, select-helpers (except \code{regex()}) and (user-defined) functions can be negated, i.e. return -non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with("")}, +non-matching elements, when prefixed with a \code{-}, e.g. \code{-ends_with()}, \code{-is.numeric} or \code{-(Sepal.Width:Petal.Length)}. \strong{Note:} Negation means that matches are \emph{excluded}, and thus, the \code{exclude} argument can be used alternatively. For instance, \code{select=-ends_with("Length")} (with @@ -94,7 +95,7 @@ treated as regular expression. When \code{regex = TRUE}, select \emph{must} be a character string (or a variable containing a character string) and is not allowed to be one of the supported select-helpers or a character vector of length > 1. \code{regex = TRUE} is comparable to using one of the two -select-helpers, \code{select = contains("")} or \code{select = regex("")}, however, +select-helpers, \code{select = contains()} or \code{select = regex()}, however, since the select-helpers may not work when called from inside other functions (see 'Details'), this argument may be used as workaround.} From 5463c93e0ae2954c95eeee4b42d27fbdf6f30fdb Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 27 Nov 2024 17:43:13 +0100 Subject: [PATCH 4/4] `data_summary()` works with `bayestestR::ci()` (#483) * Draft new `data_summary()` function * check if we can avoid duplicated code * pkgdown * fix * fixes * lintr * add tests * code style * desc, news * fix * add print method and snapshot test * add test * correct english form * test * include NA, sort output * add test * meaningful code comments * add test * Update data_summary.R * fix --- DESCRIPTION | 2 +- NEWS.md | 3 +++ R/data_summary.R | 21 ++++++++++++++++----- tests/testthat/test-data_summary.R | 23 +++++++++++++++++++++++ 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index be41e0f6f..b75f96278 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: datawizard Title: Easy Data Wrangling and Statistical Transformations -Version: 0.13.0.14 +Version: 0.13.0.15 Authors@R: c( person("Indrajeet", "Patil", , "patilindrajeet.science@gmail.com", role = "aut", comment = c(ORCID = "0000-0003-1995-6531")), diff --git a/NEWS.md b/NEWS.md index 15b7f853d..a701ba2b8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -25,6 +25,9 @@ CHANGES * The `replacement` argument in `data_rename()` now supports glue-styled tokens (#563). +* `data_summary()` also accepts the results of `bayestestR::ci()` as summary + function (#483). + BUG FIXES * `describe_distribution()` no longer errors if the sample was too sparse to compute diff --git a/R/data_summary.R b/R/data_summary.R index 546c47659..521266d61 100644 --- a/R/data_summary.R +++ b/R/data_summary.R @@ -122,7 +122,7 @@ data_summary.data.frame <- function(x, ..., by = NULL, remove_na = FALSE) { # bind grouping-variables and values summarised_data <- cbind(s[1, by], summarised_data) # make sure we have proper column names - colnames(summarised_data) <- c(by, vapply(summarise, names, character(1))) + colnames(summarised_data) <- c(by, unlist(lapply(summarise, names))) summarised_data }) out <- do.call(rbind, out) @@ -187,18 +187,24 @@ data_summary.grouped_df <- function(x, ..., by = NULL, remove_na = FALSE) { out <- lapply(seq_along(dots), function(i) { new_variable <- .get_new_dots_variable(dots, i, data) - stats::setNames(new_variable, names(dots)[i]) + if (inherits(new_variable, c("bayestestR_ci", "bayestestR_eti"))) { + stats::setNames(new_variable, c("CI", "CI_low", "CI_high")) + } else { + stats::setNames(new_variable, names(dots)[i]) + } }) } # check for correct length of output - must be a single value! - if (any(lengths(out) != 1)) { + # Exception: bayestestR::ci() + wrong_length <- !sapply(out, inherits, what = c("bayestestR_ci", "bayestestR_eti")) & lengths(out) != 1 # nolint + if (any(wrong_length)) { insight::format_error( paste0( "Each expression must return a single value. Following expression", - ifelse(sum(lengths(out) != 1) > 1, "s", " "), + ifelse(sum(wrong_length) > 1, "s", " "), " returned more than one value: ", - text_concatenate(vapply(dots[lengths(out) != 1], insight::safe_deparse, character(1)), enclose = "\"") + text_concatenate(vapply(dots[wrong_length], insight::safe_deparse, character(1)), enclose = "\"") ) ) } @@ -214,6 +220,11 @@ print.dw_data_summary <- function(x, ...) { if (nrow(x) == 0) { cat("No matches found.\n") } else { + if (all(c("CI", "CI_low", "CI_high") %in% colnames(x))) { + ci <- insight::format_table(x[c("CI", "CI_low", "CI_high")], ...) + x$CI <- x$CI_low <- x$CI_high <- NULL + x <- cbind(x, ci) + } cat(insight::export_table(x, missing = "", ...)) } } diff --git a/tests/testthat/test-data_summary.R b/tests/testthat/test-data_summary.R index c60b142d2..701fc996b 100644 --- a/tests/testthat/test-data_summary.R +++ b/tests/testthat/test-data_summary.R @@ -228,3 +228,26 @@ test_that("data_summary, extra functions", { out <- data_summary(mtcars, n = n(), by = c("am", "gear")) expect_identical(out$n, c(15L, 4L, 8L, 5L)) }) + + +test_that("data_summary, bayestestR::ci", { + skip_if_not_installed("bayestesR") + data(mtcars) + out <- data_summary( + mtcars, + mean_value = mean(mpg), + ci = bayestestR::ci(mpg), + by = c("am", "gear") + ) + expect_snapshot(out) + expect_error( + data_summary( + mtcars, + mw = mean(mpg), + test = bayestestR::ci(mpg), + yolo = c(mean(mpg), sd(mpg)), + by = c("am", "gear") + ), + regex = "Each expression" + ) +})