RE: [R] Functions within functions in R and S-Plus

2005-06-07 Thread Thomas Lumley
On Tue, 7 Jun 2005, Liaw, Andy wrote: The easiest way, perhaps, is to assign the internal functions to frame 1: Another easy way is to use the MC() function in section 3.3.1 of the R FAQ, which makes function closures in a way that works in S-PLUS. -thomas

Re: [R] Functions within functions in R and S-Plus

2005-06-07 Thread Spencer Graves
p.s. This modification gave the same answer for me in both S-Plus 6.2 and R 2.1.0 patched under Windows XP. Spencer Graves wrote: How about the following: mainfunc <- function(x){ est <- function(x,par){ abs(sum(par*x)) } func <- function(par,x, est.=est){ est.(x,par) } est.theta <- fu

Re: [R] Functions within functions in R and S-Plus

2005-06-07 Thread Spencer Graves
How about the following: mainfunc <- function(x){ est <- function(x,par){ abs(sum(par*x)) } func <- function(par,x, est.=est){ est.(x,par) } est.theta <- function(x, func.=func, est.=est){ optimize(func.,lower=-10, upper=20,x=x, est.=est.)$minimum } est.theta(x, func.

Re: [R] Functions within functions in R and S-Plus

2005-06-07 Thread Sundar Dorai-Raj
Victor Gravenholt wrote: Sorry to bother you about a S-Plus related problem, but I hope someone can help. I have tried to "translate" some code from R to S-Plus (I have colleague that insists on using S-Plus. And yes, I have tried to make him change to R...) The following code works out fine

RE: [R] Functions within functions in R and S-Plus

2005-06-07 Thread Liaw, Andy
The easiest way, perhaps, is to assign the internal functions to frame 1: > mainfunc <- function(x){ + + est <- function(x,par){ + abs(sum(par*x)) + } + + func <- function(par,x){ + est(x,par) + } + + est.theta <- function(x){ + optimize(func,lower=-10, upper=20,x=x)$minimum + } +