R/utils.R

Defines functions drop_nulls loaded_pkg_version trim_ws default_r_file_pattern `%||%` get_package_name

Documented in default_r_file_pattern

get_package_name <- function(path = ".") {
  state <- parseNamespaceFile(basename(path), file.path(path, ".."))
}

`%||%` <- function(l, r) { if (is.null(l)) r else l }

#' Default pattern for R files
#' @return Regular expression.
#' @keywords internal

default_r_file_pattern <- function() {
  "\\.[RrSs]$"
}

trim_ws <- function(x) {
  sub("\\s+$", "", sub("^\\s+", "", x))
}

loaded_pkg_version <- function(pkg) {
  asNamespace(pkg)$`.__NAMESPACE__.`$spec[["version"]]
}

drop_nulls <- function(l) {
  l[ ! vapply(l, is.null, TRUE) ]
}

Try the goodpractice package in your browser

Any scripts or data that you put into this service are public.

goodpractice documentation built on Aug. 31, 2022, 1:05 a.m.