Assorted R functions and useful bits