Program-Defined Functions in R

I wrote an article titled “Program-defined Functions in R” in the April 2016 issue of Visual Studio Magazine. See


The R language is most often used in an interactive mode to perform statistical analysis on data. But for relatively complicated tasks it’s possible to write an R script that has program-defined functions (usually called user-defined functions in R).

In my article, I give a series of short examples that demonstrate:

1. Basic R function syntax resembles C# and uses the “function” and “return” keywords.
2. R function parameters are passed by value, not by reference.
3. R supports default parameter values using the “=” assignment operator.
4. R does not support C# style function name overloading.
5. R supports variable number of function arguments using the “…” token.
6. R supports recursive function definitions.
7. R supports nested function definitions with the “<<-" assignment operator.

The bottom line is that an experienced C# or Java or Python developer can pick up program-defined functions in R quite quickly. In my opinion, traditional R users would face a moderate challenge learning how to write functions correctly.

This entry was posted in R Language. Bookmark the permalink.