Skip to content

Instantly share code, notes, and snippets.

View setempler's full-sized avatar

Sven E. Templer setempler

View GitHub Profile
@setempler
setempler / function_duplicates.R
Created July 23, 2016 15:53
Detect duplicated function definitions from R source files
#!/usr/bin/env Rscript
f <- list.files("R/", full.name = TRUE) # run from package source, or adjust path
d <- lapply(setNames(f, sub("//", "/", f)), function(x)
{
x <- readLines(x)
names(x) <- seq_along(x) # tag line number
x <- sub("#.*", "", x) # delete comments
x <- sub("^[\ \t]*", "", x) # delete leading whitespace
x <- x[grepl("function", x)] # get function definitions
@setempler
setempler / rmd_knitter.R
Created March 13, 2016 11:24
Script to knit `.rmd` to `.md` to `.html` files.
library(knitr)
library(markdown)
dir <- "."
# knit R markdown to markdown
files <- list.files(dir, "\\.rmd")
for (f in files)
knit(f, sub("\\.rmd$", ".md", f), envir = new.env())
# generate html versions
@setempler
setempler / LibreOfficeXRef.lobasic
Created March 8, 2016 11:36
LibreOffice Basic macro code to format all cross reference fields with character style
Function FormatCrossReferences (cStyle As String) As Integer
'field reference and counter
r = "com.sun.star.text.TextField.GetReference"
n = 0
'enumerator for paragraph and section
Dim oParEnum
Dim oSecEnum
'current paragraph and section
Dim oPar
Dim oParSection
@setempler
setempler / bash2Darray.sh
Last active March 6, 2016 23:28
Faking two-dimensional bash arrays
#!/bin/bash
OFS=$IFS # store field separator
IFS="${2: }" # define field separator
file=$1 # input file name
unset a # reference to line array
unset i j # index
unset m n # dimension