x <- rnorm(250, 5, 2)
i <- sample.int(250, 20)
ranks <- rank(x)[i]
percentiles <- ppoints(250)[ranks]
points <- x[i]
f <- function(args, points, percentiles) {
test_quantiles <- qnorm(percentiles, args[1], args[2])
data <- mtcars
m <- lm(mpg ~ wt, data)
data <- mtcars[-c(1:10), ]
m_update <- update(m, . ~ . + disp)
nobs(m)
#> [1] 32
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
#' @param path current path of format | |
#' @param date_format date format to request from git. This format is given to | |
#' git to set the format of the dates it returns and then given to readr to | |
#' tell it how to parse the dates into date-times. | |
#' @param f_split optional function to help reduce `system()` calls. By default | |
#' (`NULL`), one `system()` call is made for each version of the file. | |
#' Alternatively, we can ask git to give the contents of the all files at once | |
#' with one `system()` call. Then `f_split()` creates a list of file contents. | |
#' @return a tibble with one row commit with commit, commit date, historical |
fct_regex_levels <- function(xs, patterns) {
default_levels <- unique(xs)
which_matches <- default_levels |>
lapply(stringr::str_which, patterns) |>
unlist()
stopifnot(
"Each factor level should have exactly one pattern" =
all(seq_along(default_levels) %in% which_matches)
)
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
is_even <- function(n) { | |
if (n == 0) list(TRUE, sys.nframe()) else Tailcall(is_odd, n - 1) | |
} | |
is_odd <- function(n) { | |
if (n == 0) list(FALSE, sys.nframe()) else Tailcall(is_even, n - 1) | |
} | |
is_odd(30) | |
naive_is_even <- function(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
bib_glance <- function(sort = TRUE) { | |
path <- "./notebook/refs.bib" | |
refs <- bibtex::read.bib(path) | |
if (sort) { | |
refs <- refs[sort(names(refs))] | |
} | |
titles <- purrr::map_chr(refs, purrr::pluck, "title") |> | |
stringr::str_replace_all("\\{|\\}", "") |> |
library(tidyverse)
#> Warning: package 'ggplot2' was built under R version 4.3.2
#> Warning: package 'dplyr' was built under R version 4.3.2
#> Warning: package 'stringr' was built under R version 4.3.2
#> Warning: package 'lubridate' was built under R version 4.3.2
Suppose we have a dataframe with labels and their locations
library(tidyverse)
library(brms)
#> Loading required package: Rcpp
#> Loading 'brms' package (version 2.19.0). Useful instructions
#> can be found by typing help('brms'). A more detailed introduction
#> to the package is available through vignette('brms_overview').
#>
#> Attaching package: 'brms'
#> The following object is masked from 'package:stats':
library(gamlss)
#> Loading required package: splines
#> Loading required package: gamlss.data
#>
#> Attaching package: 'gamlss.data'
#> The following object is masked from 'package:datasets':
#>
#> sleep
#> Loading required package: gamlss.dist
read_spectogram_file <- function(path) {
lines <- readLines(path)
powers <- lines |>
stringr::str_match("z \\[(\\d+)\\] \\[(\\d+)\\] = (\\S+) ") |>
as.data.frame() |>
stats::setNames(c("line", "y", "x", "power"))
# ugly bc i removed dplyr functions
powers <- powers[!is.na(powers$line), 2:4] |>
NewerOlder