This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(progressr) | |
library(furrr) | |
handlers("void") | |
handlers(list( | |
handler_progress( | |
format = ":spin :current/:total (:message) [:bar] :percent in :elapsed ETA: :eta", | |
width = getOption("width"), | |
complete = "=" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
invisible(lapply( | |
list.files( | |
path = ".", | |
pattern = "\\.(r|rmd|qmd)$", | |
full.names = TRUE, | |
recursive = TRUE, | |
ignore.case = TRUE | |
), | |
function(path) { | |
pat <- "!!rlang::sym[(]\"([a-zA-z0-9_]+)\"[)]" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lambda <- function(expr, args = ".i") { | |
fun <- function() { } | |
formals(fun) <- structure( | |
rep(list(substitute()), length(args)), | |
class = "alist", | |
names = args | |
) | |
if (is.function(expr)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
databricks <- local(envir = new.env(), { | |
.self <- environment() | |
.client <- NULL | |
.call <- function(method, args) { | |
if (is.null(.client)) { | |
stop( | |
"No client conigured", | |
"\nplease use $configure() function to set client", | |
call. = FALSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
x <- runif(1000) | |
plotly::plot_ly( | |
x = x, | |
type = "histogram", | |
) |> | |
plotly::layout( | |
bargap = 0.05, | |
shapes = list( | |
vline(mean(x), "mint", "mean"), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Evaluate an R6 object within its enclosed environment | |
#' | |
#' @param x An R6 object | |
#' @param expr An expression to run | |
#' @export | |
#' @examples | |
#' Foo <- R6::R6Class( | |
#' "Foo", | |
#' public = list( | |
#' hello = function() cat("hello\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# nolint start: object_usage_linter. | |
sql_snakecase0 <- function(.data, new, old = new, na = "(missing)") { | |
force(old) | |
na <- as.character(na) | |
dplyr::mutate( | |
.data, | |
!!rlang::sym(new) := tolower(!!rlang::sym(old)), | |
!!rlang::sym(new) := REGEXP_REPLACE(!!rlang::sym(new), "\\%", "percent "), | |
!!rlang::sym(new) := REGEXP_REPLACE(!!rlang::sym(new), "\\#", "n "), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vendor <- function() { | |
ns <- asNamespace("fuj") | |
writeLines( | |
unlist(sapply( | |
ls(ns), | |
function(x) { | |
format(call("assign", x, get(x, ns))) | |
} | |
)), | |
"R/fuj.R" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
largest_ns_object <- function(ns, mode = "any") { | |
ns <- asNamespace(ns) | |
sizes <- vapply( | |
ls(ns, all.names = TRUE), | |
\(x) utils::object.size(get0(x, ns, mode = mode)), | |
NA_real_ | |
) | |
sizes[which.max(sizes)] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Include exports | |
#' | |
#' Include (attach) a package and specific exports | |
#' | |
#' @description [include()] checks whether or not the namespace has been loaded | |
#' to the [search()] path. It uses the naming convention `include:{package}` | |
#' to denote the differences from loading via [library()] or [require()]. When | |
#' `exports` is `NULL`, the environment is detached from the search path if | |
#' found. When `exports` is not `NULL`, | |
#' |
NewerOlder