# Borrow from other packages ----------------------------------------------
# Rlang
`%|%` <- rlang::`%|%`
`%||%` <- function (x, y)
{
if (is.null(x))
y
else x
}
# Borrow ggplot internals
`%|W|%` <- function(a, b) {
if (!inherits(a, "waiver")) a else b
}
#' @importFrom stats setNames
#' @importFrom utils getFromNamespace
.grab_ggplot_internals <- function() {
objects <- c(
"check_breaks_labels", "default_expansion", "expand_limits_scale",
"is_position_aes", "set_sec_axis", "view_scale_primary",
"view_scale_secondary", "view_scales_from_scale", "Range"
)
objects <- setNames(objects, objects)
out <- lapply(objects, function(i) {
getFromNamespace(i, "ggplot2")
})
}
.int <- .grab_ggplot_internals()
# Blatantly stolen from the vctrs vignettes
vec_ifelse <- function(test, yes, no) {
vec_assert(test, logical())
c(yes, no) %<-% vec_cast_common(yes, no)
c(test, yes, no) %<-% vec_recycle_common(test, yes, no)
out <- vec_init(yes, vec_size(yes))
vec_slice(out, test) <- vec_slice(yes, test)
vec_slice(out, !test) <- vec_slice(no, !test)
out
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.