R/utils.R

Defines functions remove_backticks merge_vars get_vars attr_notnull_or_na notnull_or_na

notnull_or_na <- function(x) {
  if (is.null(x)) NA_character_ else x
}

attr_notnull_or_na <- function(x, at = "label") {
  notnull_or_na(attr(x, at, exact = TRUE))
}

get_vars <- function(text) {
  if (!is.null(text)) {
    all.vars(parse(text = text))
  } else {
    NULL
  }
}

merge_vars <- function(...) {
  vars_list <- list(...)
  rv <- NULL
  for (i in vars_list) {
    v <- unique(sapply(i, get_vars))
    if (length(v) > 0) rv <- union(rv, v)
  }
  rv
}

remove_backticks <- function(x) {
  gsub("^`|`$|\\\\(?=`)|`(?=:)|(?<=:)`", "", x, perl = TRUE)
}

Try the regport package in your browser

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

regport documentation built on May 10, 2022, 9:06 a.m.