[R] scope of an argument in a function

Duncan Murdoch murdoch.duncan at gmail.com
Thu Jul 15 12:36:02 CEST 2010


On 15/07/2010 3:06 AM, Raghu wrote:
> Hi
> 
> I am trying to define a function fu() in the following way but when I try to
> run I get the error that ma1 is not found. I am not sure where I am going
> wrong? Does the scope of ma1 not extend to an expr.frame object?
> expr.frame() is under library tradesys.

This is really a question for the author of tradesys.  That package is 
not on CRAN, though there's a 0.1 version package of that name on 
R-forge.  I'd suggest contacting the developers there.

Duncan Murdoch

> 
> 
> function (y,ma1,ma2)
> {
> x <- y[, c("Open","Close")]
> d <- expr.frame(x, list(MAf=quote(SMA(Close, ma1)), MAs=quote(SMA(Close,
> ma2))))
> }
> 
>> fu(spx,60,120)
> Error in runSum(x, n) : object 'ma1' not found
> 
> 
> 
> 
> Thanks for your kind help.
> 
>



More information about the R-help mailing list