Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Nov 21, 2024
1 parent 80437a3 commit c6b1500
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
8 changes: 4 additions & 4 deletions R/data_rename.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
#' vector using `<new name> = "<old name>"` and argument `replacement` will
#' be ignored then).
#' @param replacement Character vector. Can be one of the following:
#' - A character vector that indicates the new name of the columns selected in
#' `pattern`. `pattern` and `replacement` must be of the same length.
#' - `NULL`, in which case column are numbered in sequential order.
#' - 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 "curl" styled pattern.
#' Currently supported tokens are `{col}` and `{n}`. `{col}` will be replaced
#' by the column name, i.e. the corresponding value in `pattern`. `{n}` will
Expand All @@ -34,7 +34,7 @@
#' replacement = "new_name_from_{col}"
#' )
#' ```
#' would returns new column names `new_name_from_am` and `new_name_from__vs`.
#' would returns new column names `new_name_from_am` and `new_name_from_vs`.
#' See 'Examples'.
#'
#' If `pattern` is a named vector, `replacement` is ignored.
Expand Down
8 changes: 4 additions & 4 deletions man/data_rename.Rd

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

11 changes: 11 additions & 0 deletions tests/testthat/test-data_rename.R
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,14 @@ test_that("data_rename preserves attributes", {

expect_named(a1, names(a2))
})


# curl-styled pattern --------------------------

test_that("data_rename curl-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"))
})

0 comments on commit c6b1500

Please sign in to comment.