Skip to content

Instantly share code, notes, and snippets.

View traversc's full-sized avatar

Travers traversc

View GitHub Profile
@traversc
traversc / geom_smooth_monotonic.R
Created August 15, 2025 23:58
geom_smooth_monotonic
# ggplot2 + scam monotonic smoother
# alpha works on the line when se = FALSE
# Depends: ggplot2, scam
StatSmoothMonotonic <- ggplot2::ggproto(
"StatSmoothMonotonic", ggplot2::Stat,
required_aes = c("x", "y"),
compute_group = function(data, scales,
se = TRUE, level = 0.95, n = 100,
k = 10, dir = c("increasing","decreasing"),
@traversc
traversc / edlibR_example.cpp
Created July 17, 2025 23:21
edlibR Rcpp script example
#include <Rcpp.h>
#include "edlib_external.h"
// [[Rcpp::depends(edlibR)]]
using namespace Rcpp;
// [[Rcpp::export]]
List edlib_test_basic() {
// simple example
std::string query = "GATTACA";
@traversc
traversc / sakura_benchmark.R
Last active April 21, 2025 02:44
Sakura multiclass hashmap benchmark
library(sakura)
library(microbenchmark)
library(dplyr)
class_names <- sapply(1:48, function(i) {
paste0("class", i)
})
sfuncs <- lapply(1:48, function(i) {
function(x) as.raw(i)
@traversc
traversc / nanonext_qs_plot.R
Last active November 14, 2024 22:42
nanonext qs bench
library(ggplot2)
library(dplyr)
library(qs2)
LEN <- 2^30 / 8
set.seed(314156); data <- rnorm(LEN) + seq(1,LEN,1) # 1 GB
qs_send <- 4.40 # seconds
serialize_send <- 1.94
qs_size <- length(qs_serialize(data, compress_level = 1, nthreads=4)) # 852 MB
serialize_size <- length(serialize(data, connection = NULL)) # 1 GB
total_time <- Sys.time()
suppressMessages(library(Rcpp))
suppressMessages(library(dplyr))
suppressMessages(library(data.table))
suppressMessages(library(qs))
suppressMessages(library(stringfish))
options(warn = 1)
do_gc <- function() {
@traversc
traversc / bench_stringi.R
Last active March 27, 2022 00:49
Benching stringi with and without altrep
library(stringi) # devtools::install_github("traversc/stringi")
library(tictoc)
enwik8 <- readLines("~/Downloads/enwik8", warn = F)
search <- c("Wikipedia", "^.")
replace <- c("Encyclopedia", "")
tic("WITHOUT alt rep")
stri_use_alt_rep(FALSE); result <- stri_replace_all_regex(enwik8, search, replace, vectorize_all = F)
toc()
@traversc
traversc / simple_progress.h
Last active September 16, 2021 05:34
Rcpp Simple Progress
#include <atomic>
#include <thread>
#include <Rcpp.h>
#include <R_ext/Print.h>
using namespace Rcpp;
class simple_progress {
private:
const size_t max;
std::atomic<size_t> counter;
library(qs)
library(data.table)
library(dplyr)
library(ggplot2)
library(fst)
library(patchwork)
library(ggformula)
library(hrbrthemes)
library(Rcpp)
library(trqwe)
#include <sys/types.h>
#include <sys/stat.h>
#include <io.h>
#include <fcntl.h>
#include <string.h>
#include <array>
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::plugins(cpp11)]]
@traversc
traversc / fdtest.cpp
Created July 24, 2019 21:02
Using file descriptors directly in R
#include <cerrno>
#include <fcntl.h>
#include <cstdio>
#include <unistd.h>
#include <string.h>
#include <array>
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::plugins(cpp11)]]