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 to generate random 3D points within a defined space | |
initialize_swarm = function(n=100, range=10) { | |
swarm = matrix(runif(n * 3, -range, range), ncol=3) | |
velocities = matrix(runif(n * 3, -0.1, 0.1), ncol=3) | |
list(swarm=swarm, velocities=velocities) | |
} | |
spinning_vector_field = function(swarm, spin_strength=0.05) { | |
#Swirl around the Z-axis |
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
`[.vec` <- function(x, i, ...) { | |
UseMethod("[.vec", i) | |
} | |
`[<-.vec` <- function(x, i, value, ...) { | |
UseMethod("[<-.vec", i) | |
} | |
`[.vec.default` <- function(x, i, ...) { | |
class(x) <- setdiff(class(x), "vec") |
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
#' Produce a list of all GitHub contributors to a project | |
#' | |
#' If you want a way to give thanks to specific people who have contributed to a project | |
#' since a given release, this will extract the GitHub user names from a given package's | |
#' NEWS file. This assumes that 1) the package has a `NEWS.md` file and 2) the package | |
#' uses level 1 headers and semantic versioning for each version in the news file. | |
#' | |
#' @param package the name of a package | |
#' @param since a version number (must match a version recorded in the NEWS) | |
#' @return a character vector with GitHub user names |
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
library(ggforce) | |
library(purrr) | |
library(tibble) | |
library(gganimate) | |
web_strand <- function(side = 1, bend = 0.5, angle = 0, start = c(0,0)){ | |
pos <- cbind(x=c(0, 1, 2), y = bend*c(0, 2, 0)) | |
post <- pos %*% matrix(c(cos(angle), -sin(angle), sin(angle), cos(angle)), ncol=2, byrow=TRUE) | |
xt <- post[,1] + start[1] | |
yt <- post[,2] + start[2] |
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
# GAM model with a local smoother | |
library(tidyverse) | |
set.seed(2) | |
elapsed <- arima.sim(model = list(order = c(0, 1, 0)), n=200) + 20 | |
elapsed <- pmax(elapsed, 1) | |
data <- tibble( | |
x = 1:201, | |
elapsed = elapsed | |
) | |
plot(data) |
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
# This is now available into ggpercentogram. | |
# https://github.com/eliocamp/ggpercentogram/ | |
StatQuantileBin <- ggplot2::ggproto("StatQuantileBin", ggplot2::StatBin, | |
default_aes = ggplot2::aes(x = ggplot2::after_stat(density), y = ggplot2::after_stat(density), weight = 1), | |
compute_group = function(data, scales, | |
binwidth = NULL, bins = 30, breaks = NULL, trim = 0, | |
closed = c("right", "left"), pad = FALSE, | |
flipped_aes = FALSE, | |
# The following arguments are not used, but must | |
# be listed so parameters are computed correctly |
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
require(rang) | |
require(purrr) | |
require(igraph) | |
convert_edgelist <- function(x) { | |
output <- data.frame(x = x$pkg, y = rang:::.extract_queryable_dependencies(x$original, x$no_enhances, x$no_suggests)) | |
for (dep in x$deps) { | |
if (!rang:::.is_terminal_node(dep, x$no_enhances)) { | |
el <- data.frame(x = unique(dep$x_pkgref), y = rang:::.extract_queryable_dependencies(dep, x$no_enhances, x$no_suggests)) | |
output <- rbind(output, el) |
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
library(withr) | |
library(data.table) | |
r_dir <- "~/github/r-svn" | |
all_commits <- with_dir(r_dir, system('git log --pretty="format:%H %b"', intern=TRUE)) | |
all_commits <- all_commits[nzchar(all_commits)] | |
hashes <- substr(grep("^[0-9a-f]{40} ", all_commits, value=TRUE), 1, 40) | |
trunk_hash <- head(hashes, 1L) | |
# grep("trunk@33000", all_commits, value = TRUE) |
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/local/bin/Rscript | |
library(potools) | |
suppressPackageStartupMessages(library(data.table)) | |
script_wd = setwd("~/github/r-svn") | |
GIT_COMMIT = if (interactive()) readline('git commit: ') else commandArgs(TRUE) | |
setwd('src/library') | |
get_po_messages <- potools:::get_po_messages |
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
set_invisible_attr <- function(x, ...) { | |
x_chr <- as.character(substitute(x)) | |
pf <- parent.frame() | |
if(bindingIsActive(x_chr, pf)) { | |
env <- environment(activeBindingFunction(x_chr, pf)) | |
args <- list(...) | |
env$closure$attrs[names(args)] <- args | |
return(x) | |
} |
NewerOlder