Helper functions in R