[R] Clash between alr3 and AlgDesign. (Was: Re: Second & subsequent calls to function fails. Please help debug.)

Michael Kubovy kubovy at virginia.edu
Sun Mar 30 19:48:01 CEST 2008


Hi Duncan,

Yes, I came to realize that ifelse was not the way to go. Here is how  
I dealt with it:

if(sum('AlgDesign' == (.packages())) > 0) detach('package:AlgDesign')

It requires me (and my students) to learn only the (.packages())  
construct (and avoid knowing anything about search(), match() or pos).  
As a former student of mine (who has long since gone into business)  
once said: "I avoid learning experiences like the plague."

Thanks again,
Michael

On Mar 30, 2008, at 1:36 PM, Duncan Murdoch wrote:

> On 30/03/2008 10:06 AM, Michael Kubovy wrote:
>> I've been trying to dynamically detach and attach things in my  
>> Sweave,  in order to circumvent the problem.
>> Here is my first attempt:
>> pkg <- 'package:AlgDesign'
>> p <- is.na(match(pkg, search()))
>> ifelse(p  == FALSE, detach(pkg), NA)
>
> You can't use detach this way.  It is fine to say  
> detach("package:AlgDesign") or detach(AlgDesign), but the way detach  
> is written, you're attempting to detach something named "pkg".
>
> This rewrite of your code is untested, but I think it should work:
>
> pkg <- 'package:AlgDesign'
> p <- match(pkg, search())
> if (!is.na(p)) detach(pos=p)
> require(alr3)
>
> I've also changed your ifelse() to if (), and not just because I  
> don't need an else clause:  ifelse() is designed to do computations  
> on vectors, if() is designed for flow control.  I think we want flow  
> control here.
>
> Duncan Murdoch

_____________________________
Professor Michael Kubovy
University of Virginia
Department of Psychology
USPS:     P.O.Box 400400    Charlottesville, VA 22904-4400
Parcels:    Room 102        Gilmer Hall
         McCormick Road    Charlottesville, VA 22903
Office:    B011    +1-434-982-4729
Lab:        B019    +1-434-982-4751
Fax:        +1-434-982-4766
WWW:    http://www.people.virginia.edu/~mk9y/



More information about the R-help mailing list