This file contains hidden or 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
cli_args <- function(...) { | |
x <- list(...) | |
nm <- names(x) | |
stopifnot(all(nm != "")) | |
single <- nchar(nm) == 1L | |
nm[single] <- paste0("-", nm[single]) | |
nm[!single] <- paste0("--", gsub("[[:punct:][:space:]]", "-", nm[!single])) | |
paste(nm, x, collapse = " ") | |
} |
This file contains hidden or 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
numbers <- function(big = 2L, small = 6L - big) { | |
stopifnot(big + small == 6L) | |
c(sample(50:100, big), sample(0:49, small)) | |
} | |
problem <- function(x = numbers(), parenthesis = TRUE, ns = length(x)) { | |
stopifnot(all(ns > 1), all(ns <= length(x))) | |
x <- as.integer(x) |
This file contains hidden or 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
# You'll need to change {pkg} here for your package because I'm too lazy to generalize this right now | |
# I'll probably put this in jmbarbone/mark or jmbarbone/markExtra | |
#' Add code snippets | |
#' | |
#' Adds code snippets | |
#' | |
#' @export | |
add_pkg_snippets <- function() { |
This file contains hidden or 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
# vector filtering -------------------------------------------------------- | |
# Modeled from `base::Filter()` but less generalized (therefore more efficient). | |
# These functions also use a vector as the first argument rather than the | |
# filtering function. | |
base::Filter | |
#> function (f, x) | |
#> { | |
#> f <- match.fun(f) |
This file contains hidden or 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
rank_limited <- function(x, method = c("auto", "shell", "quick", "radix")) { | |
u <- sort(unique(x), method = method) | |
match(x, u) | |
} | |
rank_limited2 <- function(x, method = c("auto", "shell", "quick", "radix")) { | |
u <- unique(sort(x, method = method)) | |
match(x, u) | |
} |
This file contains hidden or 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
# original ---------------------------------------------------------------- | |
new <- list() # construct as list -- data.frames are fancy lists | |
cols <- c(1, 5, 3) # use a vector of column indices | |
for (i in seq_along(cols)) { | |
# append the list at each column | |
new[[i]] <- mtcars[, cols[i], drop = FALSE] | |
} | |
new <- as.data.frame(new) # make list into data.frame |
This file contains hidden or 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
#! /usr/bin/env sh | |
# Based on https://serebrov.github.io/html/2019-06-16-git-hook-to-add-issue-number-to-commit-message.html | |
# | |
# This hook works for branches named such as "123-description" and will add "#123 " to the commit message. | |
# | |
# 123-description >> #123 | |
# | |
# Example: | |
# | |
# ``` |
This file contains hidden or 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
``` r | |
jira_table_paste <- function(data, quiet = FALSE) { | |
stopifnot(is.data.frame(data), all(!sapply(data, is.list))) | |
data[] <- lapply(data, function(i) paste0("{{", i, "}}")) | |
data <- rbind(matrix(colnames(data), nrow = 1L), as.matrix(data)) | |
data[] <- apply(data, 2L, function(i) format(paste0(" ", i, " "))) | |
res <- c( | |
# the headers come out as a little annoying | |
paste0("||", paste0(data[1L, ], collapse = "||"), "||"), | |
paste0("|", apply(data[-1L, ], 1L, paste0, collapse = "|"), "|") |
This file contains hidden or 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
#' Render quarto files | |
#' | |
#' Render quarto files | |
#' | |
#' @details | |
#' The `.qmd` input file is copied as a temporary file, which is then used for | |
#' rendering. The output of this is then copied over to the intended output | |
#' file. | |
#' |
This file contains hidden or 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
detach_recursive <- function(name, ...) { | |
stopifnot(!missing(name), is.character(name)) | |
params <- list(...) | |
params$name <- name | |
params$character.only <- TRUE | |
repeat { | |
if (inherits(try(do.call(detach, params), silent = TRUE), "try-error")) { | |
break | |
} |