R/utils.R

Defines functions is_installed set_names strw_count

# TODO
# add tests

# from rlang::is_installed()
is_installed <- function(pkg) {
  identical(requireNamespace(pkg, quietly = TRUE), TRUE)
}

set_names <- function(x, nm) {
  names(x) <- nm
  x
}

strw_count <- function(string, pattern, perl = FALSE, fixed = FALSE) {
  out <- nchar(string) - nchar(gsub(pattern, "", string, perl = perl, fixed = fixed))
  out / nchar(pattern)
}
rwright88/rwmisc documentation built on Dec. 14, 2019, 5:31 p.m.