andreas' R script