R helper functions