R: Passing function arguments to override defaults of inner functions -


in r, this: have function f1, has argument default value; k=3.

f1 = function(x,k=3){     u=x^2+k     u } 

i later define second function, f2 calls f1.

f2 = function(z,s){     s*f1(z) } 

what's cleanest way allow users of f2 override default value of k in inner function f1? 1 trivial solution redefine f2 as:

f2 = function(z,s,k){     s*f1(z,k) } 

however, feel might cumbersome if i'm dealing large heirarchy of functions. suggestions? thanks.

the easiest way deal using ... argument. allows pass number of additional arguments other functions:

f1 = function(x,k=3){     u=x^2+k     u }  f2 = function(z,s, ...){     s*f1(z, ...) } 

you'll see commonly used in functions call others many optional arguments, example plot.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -