codes:
test<-function(x=1,y=lv*3) {
lv<-1
x+y
}
test()
4
test(2)
5
test(1,1)
2
now have some change:
test<-function(x=1,y=lv*3) {
cat(x+y,"\n")
lv<-1
x+y
}
test()
Error in cat(x + y, "\n") : object 'lv' not found
So, a function's local variable can be used to initialize the function's (default)parameter once that local variable has been initialized.