Skip to content

Commit

Permalink
refactor: move assertions to own file
Browse files Browse the repository at this point in the history
  • Loading branch information
m-muecke committed May 1, 2024
1 parent 050f9b1 commit 4e25873
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
20 changes: 20 additions & 0 deletions R/assertions.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
is_character <- function(x) {
is.character(x) && !anyNA(x) && length(x) > 0L
}

is_string <- function(x) {
is.character(x) && length(x) == 1L && !is.na(x)
}

is_string_or_null <- function(x) {
is.null(x) || is_string(x)
}

is_count <- function(x) {
is.numeric(x) && length(x) == 1L && !is.na(x) &&
as.integer(x) == x && x > 0L
}

is_count_or_null <- function(x) {
is.null(x) || is_count(x)
}
21 changes: 0 additions & 21 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,6 @@ as_tibble <- function(x) {
}
}

is_character <- function(x) {
is.character(x) && !anyNA(x) && length(x) > 0L
}

is_string <- function(x) {
is.character(x) && length(x) == 1L && !is.na(x)
}

is_string_or_null <- function(x) {
is.null(x) || is_string(x)
}

is_count <- function(x) {
is.numeric(x) && length(x) == 1L && !is.na(x) &&
as.integer(x) == x && x > 0L
}

is_count_or_null <- function(x) {
is.null(x) || is_count(x)
}

na_if_empty <- function(x, empty = "") {
replace(x, x == empty, NA_character_)
}
Expand Down

0 comments on commit 4e25873

Please sign in to comment.