[R] variable scope for deltavar function from emdbook

adad adad at gmx.at
Mon Oct 10 13:41:44 CEST 2011


Dear all,

I want to use the deltavar() function from emdbook. I can use it 
directly from the command terminal but within a function it behaves weird.

Working example:
----------------------
library("emdbook")

fn <- function()
{
browser()
y <- 2
print(deltavar(y*b2, meanval=c(b2=3), Sigma=1) )
}

x <- 2
print(deltavar(x*b1, meanval=c(b1=3), Sigma=1) )
y<-3

fn()
------------------------

running this returns 4 for the first function call, which is fine.

For the call of deltavar in fn(), I get 9, i.e. the function uses y<-3 
instead of the local y<-2. If y<- is commented, deltavar returns an error.

So why is the function not using the local variable and how do I make it 
use it?

Many thanks



More information about the R-help mailing list