Skip to content

Instantly share code, notes, and snippets.

View llrs's full-sized avatar

Lluís Revilla llrs

View GitHub Profile
@zkamvar
zkamvar / give_thanks.R
Created November 21, 2023 23:43
Give thanks to contributors of a project
#' 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
@baptiste
baptiste / hexaweb.R
Last active November 10, 2023 16:40
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]
@jrosell
jrosell / anomalies.R
Last active August 23, 2023 10:53
Detect anomalies over time using percentiles and using a GAM model with a local smoother or Isolation Forest model
# 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)
@eliocamp
eliocamp / StatQuantileBin.R
Last active July 24, 2023 13:50
Percentogram (histogram with bins of equal number of observations)
# 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
@chainsawriot
chainsawriot / rang.R
Last active February 16, 2023 16:27
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)
@MichaelChirico
MichaelChirico / get_r_translation_status.R
Created April 26, 2022 07:12
Execute a run of snapshot summaries for translations, then visualize
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)
@MichaelChirico
MichaelChirico / get_r_translation_status_for_revision.R
Created April 26, 2022 07:11
Summarize the state of translation for a snapshot of r-devel
#!/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
@moodymudskipper
moodymudskipper / invisible_attributes.R
Created April 4, 2022 16:29
invisible attributes
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)
}
@TG9541
TG9541 / R-on-RaspPi-Zero-W.md
Last active January 17, 2024 10:23
Using R on a Raspberry Pi Zero W

Using R on a Raspberry Pi Zero W

Using R on an embedded device might sound like a wacky thing to do but for "small scale data analytics" and for learning to analyze real-world data (e.g. using JAGS or STAN) it's a good match.

Yes, compared to a PC it's relatively slow - but consider this:

  • it runs on small power budget (maybe 0.5W when idling)
  • it has a hardware watchdog which makes it more likely that it can run for many months unattended
  • Raspbian-lite is based on Debian and it comes with all kinds of well tested tools and applications
library(tidycensus)
library(ggiraph)
library(tidyverse)
library(patchwork)
vt_income <- get_acs(
geography = "county",
variables = "B19013_001",
state = "VT",
year = 2019,