[R] I don't understand this

Peter Dalgaard BSA p.dalgaard at biostat.ku.dk
Tue Sep 2 20:56:24 CEST 2003


Barry Rowlingson <B.Rowlingson at lancaster.ac.uk> writes:

> Peter Dalgaard BSA wrote:
> 
> > BTW: If you ever actually need to do something like that, try
> > eval(substitute(foo(x)<-10,list(foo=as.name(if (cond) "names" else
> > "dim"))))
> 
> please nooooo!!! What's wrong with:
> 
>   if(cond){
>     names(x) <- 10
>    } else {
>     dim(x) <- 10
>   }
> 
>   readable, obvious, maintainable, 'portable' for some value of
> 'portable'....

Well, there's nothing nonportable with my suggestion either. I thought
that "ever actually need to" would suffice to indicate that I wasn't
suggesting it as good programming practice. 

Nothing wrong with your code, except perhaps generality; I was
thinking in terms of "function that specifies which replacement
function to use", which could involve a larger set of possible
functions than names()<- and dim()<-. 

However, I'd be hard pressed to come up with a case where this would
occur in practice.

-- 
   O__  ---- Peter Dalgaard             Blegdamsvej 3  
  c/ /'_ --- Dept. of Biostatistics     2200 Cph. N   
 (*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)             FAX: (+45) 35327907




More information about the R-help mailing list