A few helpful R functions