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
| # function has been repurposed | |
| # a few edits from the original have been made without testing | |
| #' Run length encode | |
| #' | |
| #' Encodes a run length and returns the start and stop | |
| #' | |
| #' @param x A vector of values for compute the length of the run | |
| #' @param times If `NULL` will use the position of the start and stop runs, | |
| #' otherwise will return the values returned; if not `NULL`, must be equal |
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
| x <- psych::sat.act$ACT | |
| y <- psych::sat.act$SATQ + psych::sat.act$SATV | |
| ft <- equate::freqtab(data.frame(x, y)) | |
| eq0 <- equate::equate( | |
| x = ft, | |
| type = "equipercentile", |
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
| spearman_ci <- function(x, y, alpha = 0.95, method = c("norm", "t")) { | |
| # modified from https://stats.stackexchange.com/questions/18887/how-to-calculate-a-confidence-interval-for-spearmans-rank-correlation/506367#506367 | |
| method <- mark::match_param(method) | |
| ok <- stats::complete.cases(x, y) | |
| x <- x[ok] | |
| y <- y[ok] | |
| r <- cor(x, y, method = "spearman") | |
| n <- sum(ok) | |
| q <- switch( | |
| method, |
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
| text <- { | |
| " | |
| Line 1 \n info | |
| Line 2 \n info | |
| Line 3 | |
| Line 4 | |
| " | |
| } | |
| print(text) | |
| #> [1] "\n Line 1 \n info\n Line 2 \n info\n Line 3\n Line 4\n " |
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 | |
| } |
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
| ``` 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
| #! /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
| # 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
| 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) | |
| } |