Re: [R] changing default arguments of a function and return the modified function as a result

2009-06-27 Thread baptiste auguie
see also `%but%.character` in the operators package. >rnorm %but% list( mean = 3 ) function (n, mean = 3, sd = 1) .Internal(rnorm(n, mean, sd)) baptiste [[alternative HTML version deleted]] __ R-help@r-project.org mailing list https://stat.

Re: [R] changing default arguments of a function and return the modified function as a result

2009-06-26 Thread Gabor Grothendieck
Look at the source code to the Defaults package. On Fri, Jun 26, 2009 at 12:52 PM, Miguel Bernal wrote: > Dear R-users, > > I am trying to develop a function that takes another function as an argument, > changes its default values and returns a list of things, among which the > initial function wi

Re: [R] changing default arguments of a function and return the modified function as a result

2009-06-26 Thread Miguel Bernal
That was indeed what i was looking for (thanks also for the currying cite). I also wanted flexibility on the number of arguments you can pass to the function, which can be achieved by: myfun <- function(x, a=19, b=21){ return(a * x + b) } mysecond.fun <- function(dumb1, dumb2, cc=myfun, cc.ar

Re: [R] changing default arguments of a function and return the modified function as a result

2009-06-26 Thread baptiste auguie
Is this what you want? myfun <- function(x, a=19, b=21){ return(a * x + b) } mysecond.fun <- function(a, b, cc=myfun, cc.args=list(a=2,b=15) ){ list(a=a, b=b, cc = function(x) cc(x, cc.args$a, cc.args$b)) } mysecond.fun(a=1,b=2)$cc(x=12) It may be that you're after a Curry (*) function, as in,

Re: [R] changing default arguments of a function and return the modified function as a result

2009-06-26 Thread David Winsemius
On Jun 26, 2009, at 12:52 PM, Miguel Bernal wrote: Dear R-users, I am trying to develop a function that takes another function as an argument, changes its default values and returns a list of things, among which the initial function with its default arguments changed. An example of what

[R] changing default arguments of a function and return the modified function as a result

2009-06-26 Thread Miguel Bernal
Dear R-users, I am trying to develop a function that takes another function as an argument, changes its default values and returns a list of things, among which the initial function with its default arguments changed. An example of what i will like to obtain below: ## initial function myfun