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

From: Michael Kubovy <kubovy_at_virginia.edu>
Date: Sun, 30 Mar 2008 13:48:01 -0400

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/

R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Sun 30 Mar 2008 - 18:01:14 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 30 Mar 2008 - 18:30:26 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive