Skip to content

Commit

Permalink
closes #40
Browse files Browse the repository at this point in the history
  • Loading branch information
jmbarbone committed Aug 31, 2021
1 parent ddf34ce commit ba81c90
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* adds `detail()` to return a `data.frame` of details for a vector of columns of a `data.frame`
* updates to file path finding functions (e.g., `list_files()`) to try to not search every file depending on desired searches (e.g., by full file paths or just base names)
* adds `squash_vec()` to combined the names of a vector with repeated values
* `set_names0(NULL)` no longer causes an error and returns `NULL` [#40](https://github.com/jmbarbone/mark/issues/40)

# mark 0.2.0

Expand Down
3 changes: 2 additions & 1 deletion R/names.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ sort_names <- function(x, numeric = FALSE) {
#' @param x A vector of values
#' @param nm A vector of names
#' @return
#' * `set_names0()`: `x` with `nm` values assigned to names
#' * `set_names0()`: `x` with `nm` values assigned to names (if `x` is `NULL`, `NULL` is returned)
#' * `remove_names()`: `x` without names
#' * `names_switch()`: `character` vector of equal length `x` where names and values are switched
#'
#' @export
set_names0 <- function(x, nm = x) {
if (is.null(x)) return(NULL)
`names<-`(x, nm)
}

Expand Down
2 changes: 1 addition & 1 deletion man/set_names0.Rd

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

4 changes: 4 additions & 0 deletions tests/testthat/test-names.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
test_that("set_names0() works", {
expect_null(set_names0(NULL))
})

test_that("names_switch() works", {
x <- c(a = 1, b = 2, c = 3)
y <- names(x)
Expand Down

0 comments on commit ba81c90

Please sign in to comment.