fooReferenceClass <- setRefClass(
"fooReferenceClass",
fields = list(
private = "environment",
n = "integer"
)
)
# create a list of values that will be transfered to private. alternatively,
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
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 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 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 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 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
datarows <- function(...) { | |
ls <- list(...) | |
w <- which(vapply(ls, inherits, NA, "formula")) | |
n <- length(w) | |
cols <- as.character(ls[w]) | |
cols <- substr(cols, 2, nchar(cols)) | |
ls <- ls[-w] | |
sa <- seq_along(ls) | |
sa <- (sa - 1) %% n | |
res <- lapply(split(ls, sa), unlist) |
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 <- c("apple", "banana", "orange", "pear", "grape") | |
p <- "[aeoiu][^(aeiou)]" | |
regexpr(p, x) # integer vector | |
#> [1] 1 2 1 3 3 | |
#> attr(,"match.length") | |
#> [1] 2 2 2 2 2 | |
#> attr(,"index.type") | |
#> [1] "chars" | |
#> attr(,"useBytes") |
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
do_call <- function(fun, ...) { | |
fun <- match.fun(fun) | |
forms <- as.list(formals(fun)) | |
params <- list(...) | |
nms <- names(params) | |
o <- order(match(nms, names(forms))) | |
params <- params[o] | |
nms <- nms[o] |
df <- palmerpenguins::penguins
bench::mark(
rowwise = df |>
dplyr::rowwise() |>
dplyr::mutate(sum = sum(dplyr::c_across(c(bill_length_mm, bill_depth_mm, flipper_length_mm, body_mass_g)))) |>
dplyr::ungroup(),
rowSums = df |>
do.call(rbind, lapply(
list(
integer = 1L,
integerish = 1.0,
double = 1.1,
factor = factor("a"),
date_double = structure(19486, class = "Date"),
date_integer = structure(19486L, class = "Date"),
time_double = structure(1683663687, class = c("POSIXct", "POSIXt")),