useful snippets and functions for R