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

2008-03-31 Thread Martin Oliver Sailer
Dear all,

thanks for the advice. The latest version of crossdes (1.0-8) on CRAN  
now has namespaces. Hope this helps.

Regards
Oliver Sailer
 

Duncan Murdoch schrieb:
 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

-- 
--
 Dipl.-Stat. Oliver Sailer
 Fakultät Statistik
 Technische Universität Dortmund

 D-44221 Dortmund

 Tel.: ++49 (0)231 755 - 5409
 Fax:  ++49 (0)231 755 - 3454

 E-Mail: [EMAIL PROTECTED]

__
R-help@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.


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

2008-03-30 Thread Michael Kubovy
Thanks, Duncan,

I started a new session under the suspicion that packages were clashing.
#
# RUN 1
#
require(faraway)
# Loading required package: faraway
data(oatvar)
ov.lm - lm(yield ~ variety + block, oatvar)
require(alr3)
# Loading required package: alr3
out - tukey.nonadd.test(ov.lm)
#
# RUN 1 OK
# RUN 2
#
require(HH)
#Loading required package: HH
#Loading required package: lattice
#
#Attaching package: 'lattice'
#
#
#   The following object(s) are masked from package:faraway :
#
#melanoma
#
#Loading required package: grid
#Loading required package: multcomp
#Loading required package: mvtnorm
#
#Attaching package: 'HH'
#
#
#   The following object(s) are masked from package:alr3 :
#
#residual.plots
#
#
#   The following object(s) are masked from package:faraway :
#
#vif,
#vif.default,
#vif.lm
#
out - tukey.nonadd.test(ov.lm)
#
# RUN 2 OK
# RUN 3
#
require(crossdes)
#Loading required package: crossdes
#Loading required package: AlgDesign
#Loading required package: gtools
#
#Attaching package: 'gtools'
#
#
#   The following object(s) are masked from package:faraway :
#
#logit
#
#Loading required package: MASS
#Loading required package: grDevices
out - tukey.nonadd.test(ov.lm)
#Error in parse(text = x) :
#  unexpected symbol in yield ~ variety + block + preds(yield+variety 
+block+preds.sq)sq
#
# RUN 3 FAILS
#

#
# CHECKING FOR INTERACTION AMONG PACKAGES
#
require(MASS)
#Loading required package: MASS
#Loading required package: grDevices
out - tukey.nonadd.test(ov.lm)
require(gtools)
#Loading required package: gtools
#
#Attaching package: 'gtools'
#
#
#   The following object(s) are masked from package:faraway :
#
#logit
#
#
out - tukey.nonadd.test(ov.lm)
#
# alr3 pays well with MASS, grDevices, gtools
#
require(AlgDesign)
#Loading required package: AlgDesign
out - tukey.nonadd.test(ov.lm)
#Error in parse(text = x) :
#  unexpected symbol in yield ~ variety + block + preds(yield+variety 
+block+preds.sq)sq
require(crossdes)
#Loading required package: crossdes
out - tukey.nonadd.test(ov.lm)
#Error in parse(text = x) :
#  unexpected symbol in yield ~ variety + block + preds(yield+variety 
+block+preds.sq)sq
#
# BAD INTERACTION BETWEEN alr3 and AlgDesign
#

What now?

_
Professor Michael Kubovy
University of Virginia
Department of Psychology
USPS: P.O.Box 400400Charlottesville, VA 22904-4400
Parcels:Room 102Gilmer Hall
 McCormick RoadCharlottesville, 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@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.


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

2008-03-30 Thread Duncan Murdoch
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

__
R-help@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.


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

2008-03-30 Thread Gabor Grothendieck
On Sun, Mar 30, 2008 at 9:43 AM, Duncan Murdoch [EMAIL PROTECTED] wrote:
 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.

Namespaces are such a pain when you don't really need them though.
Its nice just to be able to source a new version of a function and have
it immediately work with the package.  Particularly for packages that
are changing or for which there is substantial code changes in the
devel version this is very convenient and namespaces interefere with that.

Although its possible to have namespace problems as discussed in this
thread I have found that it rarely actually happens and certainly not enough
to impose it.

__
R-help@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.


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

2008-03-30 Thread Michael Kubovy
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 400400Charlottesville, VA 22904-4400
Parcels:Room 102Gilmer Hall
 McCormick RoadCharlottesville, 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@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.


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

2008-03-30 Thread Duncan Murdoch
On 30/03/2008 11:31 AM, Gabor Grothendieck wrote:
 On Sun, Mar 30, 2008 at 9:43 AM, Duncan Murdoch [EMAIL PROTECTED] wrote:
 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.
 
 Namespaces are such a pain when you don't really need them though.

I would say there is no such case.  Packages all import functions. 
Having the imports change because of unrelated code means that there is 
no way to write reliable code.

 Its nice just to be able to source a new version of a function and have
 it immediately work with the package.  Particularly for packages that
 are changing or for which there is substantial code changes in the
 devel version this is very convenient and namespaces interefere with that.

That sounds like a problem with the way we handle package code, making 
it too hard to reload a package that has had small changes made.  We 
should make it easy to make a small change to a package and reload the 
modified version.

 Although its possible to have namespace problems as discussed in this
 thread I have found that it rarely actually happens and certainly not enough
 to impose it.

I suspect it happens more than people realize, and that in some cases 
they just get the wrong answers, without any helpful error message to 
let them know about it.

Duncan Murdoch

__
R-help@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.


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

2008-03-30 Thread Duncan Murdoch
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

 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?
 


__
R-help@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.