how to write user-defined functions in R