Functions used in R scripts