Skip to content

Commit

Permalink
Don't trim ws in repair_names.
Browse files Browse the repository at this point in the history
Closes #47
  • Loading branch information
hadley committed Mar 18, 2016
1 parent 21c6009 commit 7afcd30
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
13 changes: 7 additions & 6 deletions R/repair-names.R
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
}
}
6 changes: 3 additions & 3 deletions man/repair_names.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions tests/testthat/test-repair_names.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) ||
Expand Down

0 comments on commit 7afcd30

Please sign in to comment.