R utility functions