How to split your program across multiple files in R
Although R programs are typically not as large as python, real programs in production can be pretty big depending on the nature of the problem. Naturally, you would want to split your source files into multiple files depending on the complexity of the program.
Including source code from other files is really easy in R. use the function source () to specify the file to be included.
# add_numbers.r
add = function ( i , j ) {
return ( i + j )
}
Now, to include the file add_numbers.r , all you have to is include it as follows.
# main.r
source ( 'add_numbers.r')
add (2,3 )