[R] Problem with modification of [.factor

Frank E Harrell Jr fharrell at virginia.edu
Fri Jul 19 13:31:25 CEST 2002


Under

platform i586-pc-linux-gnu
arch     i586             
os       linux-gnu        
system   i586, linux-gnu  
status                    
major    1                
minor    5.0    [1.5.1 not available for Mandrake 8.1]    
year     2002             
month    04               
day      29               
language R                

when I modify [.factor to change the default drop=FALSE to drop=TRUE as such:

'[.factor' <- function(x, i, drop=TRUE) {
    y <- NextMethod("[")
    class(y) <- class(x)
    attr(y, "contrasts") <- attr(x, "contrasts")
    attr(y, "levels") <- attr(x, "levels")
    if (drop) 
        factor(y)
    else y
}

I get a recursion error:

> x <- factor(1:2,1:2,c('a','b'))
> x[]

Error in inherits(x, "factor") : evaluation is nested too deeply: infinite recursion?

If anyone has an explanation/fix I would appreciate getting it.

Thanks in advance,  -Frank
-- 
Frank E Harrell Jr              Prof. of Biostatistics & Statistics
Div. of Biostatistics & Epidem. Dept. of Health Evaluation Sciences
U. Virginia School of Medicine  http://hesweb1.med.virginia.edu/biostat
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list