Skip to content

Instantly share code, notes, and snippets.

View cszang's full-sized avatar
🌳

Christian Zang cszang

🌳
View GitHub Profile
@cszang
cszang / vimrc.vim
Last active August 29, 2015 14:03
.vimrc
set nocompatible
set encoding=utf-8
set visualbell
syntax enable
set hidden
filetype plugin indent on
set showmatch
set expandtab
set tabstop=8
set softtabstop=2
# set prompt
autoload -U promptinit
promptinit
export PS1="%n@%M(%~)> "
# completion settings
autoload -U compinit
compinit
zstyle ':completion:*:descriptions' format '%U%B%d%b%u'
zstyle ':completion:*:warnings' format '%BSorry, no matches for: %d%b'
# record history and make it available for all open shells
@cszang
cszang / build_adv-r.R
Created February 20, 2015 12:16
Build Advanced R Book as Epub.
## we need the libraries bookdown, knitr, inline, markdown, pryr
system("git clone https://github.com/hadley/adv-r.git")
setwd("adv-r")
library(knitr)
embed_png <- bookdown:::embed_png
rmds <- list.files(pattern = "^.*rmd$")
sapply(rmds, function(x) knit(x))
cat("---\ntitle: Advanced R\nauthor: Hadley Wickham\nlanguage: en-US\n...\n",
file = "front_matter.txt")
## assuming we installed pandoc via cabal
@cszang
cszang / forRprofile.R
Created March 3, 2016 13:50
source R dumpfile in win R session
rs <- function() {
dumpfile <- "~/.rdump"
dump <- readLines(dumpfile)
cat(paste0("---> ", dump[1], " ... ", tail(dump, 1), "\n"))
source(dumpfile, echo = TRUE)
system("rtobottom")
}
@cszang
cszang / g_test.R
Created February 6, 2018 14:09
Simple bivariate "Gershunov-test"
library(zoo)
g_test <- function(x, y, w = 20, l = 1000) {
cor_fun <- function(x) cor(x[,1], x[,2])
## benchmark
d0 <- data.frame(x, y)
c0 <- rollapply(d0, width = w, cor_fun, by.column = FALSE)
@cszang
cszang / spawn_progressbar.R
Last active February 14, 2023 13:31
A progressbar that fits into a dplyr::mutate -> purrr::map* pipeline
library(rlang)
library(tidyr)
library(dplyr)
library(purrr)
spawn_progressbar <- function(x, .name = .pb, .times = 1) {
.name <- substitute(.name)
n <- nrow(x) * .times
eval(substitute(.name <<- dplyr::progress_estimated(n)))
x