diff --git a/R/repair-names.R b/R/repair-names.R index 9edaa5294..228c17804 100644 --- a/R/repair-names.R +++ b/R/repair-names.R @@ -1,12 +1,12 @@ #' Repair object names. #' #' \code{repair_names} ensures its input has non-missing and -#' unique names. It also strips any leading or trailing spaces. -#' Valid names are left as is. +#' unique names (duplicated names get a numeric suffix). Valid names are +#' left as is. #' #' @param x A named vector. #' @param prefix A string, the prefix to use for new column names. -#' @param sep A string, inserted between the column name and de-duplicating +#' @param sep A string inserted between the column name and de-duplicating #' number. #' @return \code{x} with valid names. #' @export @@ -41,8 +41,9 @@ repair_names <- function(x, prefix = "V", sep = "") { init_names <- function(x) { xnames <- names(x) - if (is.null(xnames)) + if (is.null(xnames)) { rep("", length(x)) - else - ifelse(is.na(xnames), "", trim_ws(xnames)) + } else { + ifelse(is.na(xnames), "", xnames) + } } diff --git a/man/repair_names.Rd b/man/repair_names.Rd index 7ef434a5f..bae3e9814 100644 --- a/man/repair_names.Rd +++ b/man/repair_names.Rd @@ -11,7 +11,7 @@ repair_names(x, prefix = "V", sep = "") \item{prefix}{A string, the prefix to use for new column names.} -\item{sep}{A string, inserted between the column name and de-duplicating +\item{sep}{A string inserted between the column name and de-duplicating number.} } \value{ @@ -19,8 +19,8 @@ number.} } \description{ \code{repair_names} ensures its input has non-missing and -unique names. It also strips any leading or trailing spaces. -Valid names are left as is. +unique names (duplicated names get a numeric suffix). Valid names are +left as is. } \examples{ repair_names(list(3, 4, 5)) # works for lists, too diff --git a/tests/testthat/test-repair_names.R b/tests/testthat/test-repair_names.R index 199917676..ba288fc32 100644 --- a/tests/testthat/test-repair_names.R +++ b/tests/testthat/test-repair_names.R @@ -45,8 +45,6 @@ test_that("repair various name problems", { # ensure we start with a "bad" state old_names <- colnames(dat) - if (!is.null(old_names)) - old_names <- trim_ws(old_names) expect_true(is.null(old_names) || any(table(old_names) > 1) || any(old_names == '' | is.na(old_names)) ||