# R code to demonstrate how functions are called in R and how they return # information to the calling code. # This is the called code that contains function definitions. # http://www.math.nyu.edu/faculty/goodman/teaching/MathFin/index.html # Author: Jonathan Goodman add = function( x, y){ # add x to y and return the result cat(" function adds ", x, " to ", y) sum = x + y cat(" giving ", sum, "\n") sum # the return value } BirthdayWish = function( name){ # name is a character string. # Put it into a longer string, # which is a nice birthday wish. BirthdayWish = paste( "Happy birthday to", name, ", NOT!\n") BirthdayWish }