R/utils.R

Defines functions url_encode is_not_empty assert_is_string

assert_is_string <- function(x) {
  name <- deparse(substitute(x))
  if (!is.character(x) || length(x) != 1 || identical(x, NA_character_)) {
    stop("`", name, "` must be a string of length 1.")
  }
}

is_not_empty <- function(x) {
  if (is.null(x)) return(FALSE)
  if (is.character(x) && !any(nzchar(x))) return(FALSE)
  TRUE
}

url_encode <- function(x) {
  if (is.null(x)) return("")
  utils::URLencode(x, reserved = TRUE)
}
machow/dbpath documentation built on Dec. 30, 2022, 8:52 p.m.