Various R scripts and functions