Generally useful R Code