Some utility functions for R