[R] A sapply() funny.

Rolf Turner rolf at math.unb.ca
Sat Jun 14 21:57:10 CEST 2003


The sapply function is refusing to return a result for what seem to
me to be mysterious reasons.  Here is a toy example:

set.seed(111)
X    <- list(x=runif(20),y=runif(20))
rvec <- seq(0.01,0.15,length=42)

foo  <- function(x,X,cc) {
	mean((X$x)^x + (X$y)^cc)
}

bar  <- function(x,a,b){a+b*x}

try.b <- sapply(rvec,bar,a=1,b=2)     # This runs without a problem and
                                      # gives a + b*rvec as expected.

try.f <- sapply(rvec,foo,X=X,cc=1/3)  # This falls over.

The error message is:

Error in get(x, envir, mode, inherits) : variable "rvec" was not found

How can ``rvec'' not be found?  Is this one of the ``improvements''
induced by the new namespace sorcery?

Version information:

> version
         _                   
platform sparc-sun-solaris2.9
arch     sparc               
os       solaris2.9          
system   sparc, solaris2.9   
status                       
major    1                   
minor    7.0                 
year     2003                
month    04                  
day      16                  
language R

					cheers,

						Rolf Turner
						rolf at math.unb.ca




More information about the R-help mailing list