R/utils.R

Defines functions is_r_file global_variables indent paste_line quote_str skip first `%??%`

`%??%` <- function(a, b) if (length(a) == 0) b else a
first <- function(x) x[[1]]
skip <- function(x, n) x[-seq_len(n)]

quote_str <- function(x, q = "\"") paste0(q, x, q)
paste_line <- function(...) paste0(c(...), collapse = "\n")
indent <- function(..., size = 2) paste0(strrep(" ", size), c(...))

global_variables <- function(...) {
  c(
    "utils::globalVariables(c(",
    indent(..., deparse(NULL)),
    "))"
  )
}

is_r_file <- function(filename) {
  ext <- toupper(tools::file_ext(trimws(filename)))
  ext == "R" %??% FALSE
}

Try the roxyglobals package in your browser

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

roxyglobals documentation built on Aug. 21, 2023, 5:14 p.m.