Skip to content

Instantly share code, notes, and snippets.

View larnsce's full-sized avatar

Lars Schöbitz larnsce

View GitHub Profile
@larnsce
larnsce / gl-id0017-ggplot2-default-scale.R
Last active July 27, 2020 09:36
Set default colour/fill scale functions via global options
# source: https://twitter.com/yutannihilat_en/status/1287402204987396096
# reference: https://ggplot2.tidyverse.org/reference/scale_colour_discrete.html
library(ggplot2)
# functions to define scaling options ----------------
scale_fill_statZH <- function() {
ggplot2::scale_fill_manual(values = statR::zhpal$zhdiagonal)
}
@larnsce
larnsce / gl-id0019-map-enframe-unnest
Last active September 3, 2020 09:21
Use names in named list as columns of tibble
# sample data
tib <- tibble(
source = rep("ABC", 5),
year = seq(2016, 2020, 1)
)
# preprare list
tib_lst <- lst(
YEM = dat,
ZMB = dat,
@larnsce
larnsce / gl-id0023-numform-format-id
Last active October 27, 2021 13:18
How to add a leading 0 for single digits in R
install.packages("numform")
seq_in <- seq(1:20)
numform::f_pad_zero(x = seq_in, width = 2)
@larnsce
larnsce / git-clearHistory
Created May 31, 2022 10:42 — forked from stephenhardy/git-clearHistory
Steps to clear out the history of a git/github repository
-- Remove the history from
rm -rf .git
-- recreate the repos from the current content only
git init
git add .
git commit -m "Initial commit"
-- push to the github remote repos ensuring you overwrite history
git remote add origin git@github.com:<YOUR ACCOUNT>/<YOUR REPOS>.git
@larnsce
larnsce / write_citation
Last active March 26, 2024 13:14
Code to add all author roles and DOI from R Package documentation DESCRIPTION file to a CITATION.cff and generate inst/CITATION
# install.packages("cffr")
library(cffr)
packageVersion("cffr")
# Hard code doi
doi <- "10.5281/zenodo.6470427"
# creates CFF with all author roles
mod_cff <- cff_create("DESCRIPTION",