# Given the name or vector of names, returns a named vector reporting
# whether each exists and is a directory.
dir.exists <- function(x) {
res <- file.exists(x) & file.info(x)$isdir
stats::setNames(res, x)
}
compact <- function(x) {
is_empty <- vapply(x, function(x) length(x) == 0, logical(1))
x[!is_empty]
}
"%||%" <- function(a, b) if (!is.null(a)) a else b
"%:::%" <- function(p, f) {
get(f, envir = asNamespace(p))
}
# Modified version of utils::file_ext. Instead of always returning the text
# after the last '.', as in "foo.tar.gz" => ".gz", if the text that directly
# precedes the last '.' is ".tar", it will include also, so
# "foo.tar.gz" => ".tar.gz"
file_ext <- function(x) {
pos <- regexpr("\\.((tar\\.)?[[:alnum:]]+)$", x)
ifelse(pos > -1L, substring(x, pos + 1L), "")
}
is_windows <- isTRUE(.Platform$OS.type == "windows")
sort_ci <- function(x) {
withr::with_collate("C", x[order(tolower(x), x)])
}
is_loaded <- function(pkg = ".") {
pkg <- as.package(pkg)
pkg$package %in% loadedNamespaces()
}
is_attached <- function(pkg = ".") {
pkg <- as.package(pkg)
!is.null(pkgload::pkg_env(pkg$package))
}
escape_special_regex <- function(x) {
chars <- c("*", ".", "?", "^", "+", "$", "|", "(", ")", "[", "]", "{", "}", "\\")
gsub(paste0("([\\", paste0(collapse = "\\", chars), "])"), "\\\\\\1", x, perl = TRUE)
}
vcapply <- function(x, FUN, ...) {
vapply(x, FUN, FUN.VALUE = character(1), ...)
}
release_bullets <- function() {
c(
'`usethis::use_latest_dependencies(TRUE, "CRAN")`',
NULL
)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.