[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 16:06:55 CEST 2008


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)
require(alr3)

My first two runs show that I've done something wrong:

 > Sweave('20080331.Rnw')
Writing to file 20080331.tex
Processing code chunks ...
  1 : term hide (label=setup)
  2 : echo term verbatim (label=oatvar)
  3 : echo term verbatim (label=oatvar1)
  4 : echo term verbatim (label=oat2wt)
  5 : echo term verbatim (label=oat2wt)
  6 : echo term verbatim (label=lm)
  7 : echo term verbatim (label=diag)
  8 : echo term verbatim (label=tukey)
  9 : echo term verbatim (label=nonad)
10 : echo term verbatim (label=efficiency)
11 : echo term verbatim (label=wear)
12 : echo term verbatim (label=wearX)
13 : echo term verbatim (label=gyd)
Loading required package: crossdes
Loading required package: AlgDesign
14 : echo term verbatim (label=2wt)
15 : echo term verbatim (label=ablm)
16 : echo term verbatim (label=abaov)
17 : echo term verbatim (label=abTukey)
18 : echo term verbatim (label=effAb)
19 : echo term verbatim (label=rabbit)
20 : echo term verbatim (label=rabbit2)
21 : echo term verbatim (label=rabbit2wt)

You can now run LaTeX on '20080331.tex'
There were 42 warnings (use warnings() to see them)
 > Sweave('20080331.Rnw')
Writing to file 20080331.tex
Processing code chunks ...
  1 : term hide (label=setup)
  2 : echo term verbatim (label=oatvar)
  3 : echo term verbatim (label=oatvar1)
  4 : echo term verbatim (label=oat2wt)
  5 : echo term verbatim (label=oat2wt)
  6 : echo term verbatim (label=lm)
  7 : echo term verbatim (label=diag)
  8 : echo term verbatim (label=tukey)

Error:  chunk 8 (label=tukey)
Error in detach(pkg) : invalid name
 > pkg
[1] "package:AlgDesign"

(1) I should learn how to fix the above code.

(2) In general, in preparing scripts, perhaps one should just ditch  
all the loaded packages at the beginning of each run, so as to insure  
that users won't get bitten by packages I had loaded but didn't do so  
explicitly in the Sweave script, *and* it would solve the current  
problem as well. Is there a straightforward way to do that?


On Mar 30, 2008, at 9:43 AM, Duncan Murdoch wrote:

> On 30/03/2008 8:43 AM, Michael Kubovy wrote:
>> Thanks, Duncan,
>> I started a new session under the suspicion that packages were  
>> clashing.
>
> ...
>
>> #########
>> # BAD INTERACTION BETWEEN alr3 and AlgDesign
>> #########
>> What now?
>
> There's not much you can do; this is up to the package authors to  
> fix. Some advice for them:
>
> alr3, crossdes, faraway, and HH don't use a namespace.  This makes  
> them very vulnerable to this sort of interaction, because they don't  
> get to choose where the functions they use come from.  They should  
> add one.
>
> In my opinion, all packages should have namespaces, and I'd like to  
> create a default one if the author doesn't.  (The default would be:  
> import what is listed in the Depends clause, export everything.)  I  
> don't think this will happen for 2.7.0, though package.skeleton  
> might start creating one.
>
> 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