Skip to content

Instantly share code, notes, and snippets.

View klmr's full-sized avatar
📦
Making your R code easier to reuse

Konrad Rudolph klmr

📦
Making your R code easier to reuse
View GitHub Profile
@klmr
klmr / appeal-to-authority.md
Last active August 27, 2015 14:34
Appeal to authority

Here’s what the first hits on a Google search for “appeal to authority” say (top list, no hit was omitted).

This fallacy is committed when the person in question is not a legitimate authority on the subject. […] The following standards are widely accepted:

  1. The person has sufficient expertise in the subject matter in question.
  2. The claim being made by the person is within her area(s) of expertise.
  3. There is an adequate degree of agreement among the other experts in the subject in question.
@klmr
klmr / bm.R
Created January 30, 2014 20:44
Benchmarking performance of row selection via `-which(…)` vs. `!…`.
> library(microbenchmark)
> m <- data.frame(a = sample.int(10, 100000, replace=T),
b = sample.int(10, 100000, replace=T))
> microbenchmark(m[-which(m[, 1] == 4 & m[, 2] == 5), ], m[! (m[, 1] == 4 & m[, 2] == 5), ])
Unit: milliseconds
expr min lq median uq max neval
m[-which(m[, 1] == 4 & m[, 2] == 5), ] 27.59480 29.64628 30.09091 30.69976 42.04620 100
m[!(m[, 1] == 4 & m[, 2] == 5), ] 29.00876 29.70103 30.41829 33.10700 42.29671 100
> m <- as.matrix(m)
microbenchmark(m[-which(m[, 1] == 4 & m[, 2] == 5), ], m[! (m[, 1] == 4 & m[, 2] == 5), ])
@klmr
klmr / a.rb
Created January 31, 2014 14:35
$ ninja examples
[4/7] AR
FAILED: ar rcs bin/libnonius.a
ar: no archive members specified
usage: ar -d [-TLsv] archive file ...
ar -m [-TLsv] archive file ...
ar -m [-abiTLsv] position archive file ...
ar -p [-TLsv] archive [file ...]
ar -q [-cTLsv] archive file ...
ar -r [-cuTLsv] archive file ...
@klmr
klmr / a.rb
Created January 31, 2014 15:04
$ ninja examples
[5/6] LINK obj/examples/example1.o
FAILED: g++ -Wall -Wextra -pedantic -Werror -std=c++11 -g -flto obj/examples/example1.o -o bin/examples/example1 -lboost_system
Undefined symbols for architecture x86_64:
"__istype(int, unsigned long)", referenced from:
std::ctype<char>::is(unsigned long, char) const in example1.o
ld: symbol(s) not found for architecture x86_64
collect2: error: ld returned 1 exit status
[5/6] LINK obj/examples/example2.o
FAILED: g++ -Wall -Wextra -pedantic -Werror -std=c++11 -g -flto obj/examples/example2.o -o bin/examples/example2 -lboost_system
@klmr
klmr / brew-config
Created January 31, 2014 16:15
Files related to gcc48 issue on 10.9
HOMEBREW_VERSION: 0.9.5
ORIGIN: https://github.com/Homebrew/homebrew.git
HEAD: 8d8763699f3b7d35b27e571e856984f49392b741
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CELLAR: /usr/local/Cellar
CPU: quad-core 64-bit sandybridge
OS X: 10.9.1-x86_64
Xcode: 5.0.2
CLT: 5.0.1.0.1.1382131676
Clang: 5.0 build 500
@klmr
klmr / Review.markdown
Last active August 29, 2015 13:56 — forked from mschubert/unix.R

Bugfixes

  • cmdescape fixes the use of parameters which contain special characters of the terminal (or spaces)
  • Regression: the updated version does not work with custom specified arguments. If this is desired, there should be an optional list parameter for this purpose.

Style fixes & Improvements

  • Single expressions do not need (and should not have) parentheses. This goes universally (and in particular, since R is a functional programming language, for functions).
  • There’s no need to forward %sed% to sed (and same for %grep%), it can be declared as an alias. In fact, the original function is somewhat redundant since operators can be called as functions.
  • Use `…` instead of '…' to specify unusual names: the former is syntactically a name while the latter is a string! It only “happens to work” because R has special lookup rules for functions when encountering a string. The same won’t work for other (non-function) objects though.
boost::optional<myClass> func(std::string const& str) {
return str.length > 5 ? 10 :
str.length < 5 ? 0 : 5;
}
@klmr
klmr / ttf-to-afm
Created March 7, 2014 16:39
Convert TTF to AFM files, fix format
#!/usr/bin/env bash
set -e
typeface="$1"
if [ "$typeface" == "" ]; then
echo >&2 "Usage: $0 typeface"
exit 1
fi
@klmr
klmr / repro.r
Created April 7, 2014 12:44
Reproducible name clash with R packages
# Reproduce a name clash with packages
# R 3.0.2
library(DESeq) # 1.14.0
x = do.call(rbind, rep(list(read.table(text='1 2\n3 4')), 10))
m = c('V1', 'V2')
cds = estimateSizeFactors(newCountDataSet(x, m))
cds1 = estimateDispersions(cds, method='blind', fitType='local')
lp = function () 42
cds2 = estimateDispersions(cds, method='blind', fitType='local')
@klmr
klmr / arrays.java
Created April 15, 2014 09:43
Binary search implementation for a primitive type in Java.
static int binarySearch(int[] arr, int key) {
Object[] arrobj = new Object[arr.length];
for (int i = 0; i < arr.length; i++)
arrobj[i] = arr[i];
Object keyobj = key;
return binarySearch(arrobj, keyobj);
}