R code from AROMA's TAPS.doc file