Re: [Rd] sum and partial argument name matching

2004-11-20 Thread Prof Brian Ripley
On Sat, 20 Nov 2004, Patrick Burns wrote:
"sum" (and  perhaps  other functions?) allows partial argument
name matching after its three-dots argument:
sum(1:4, NA, n=78, na.rm=FALSE)
[1] 10
sum(1:4, NA, n=78, na.rm=TRUE)
[1] 11
That's not `partial argument name matching', for the exact match should 
always win.  do_summary contains

ans = matchArg(R_NaRmSymbol, &args);
and that is defined as
/* Destructively Extract A Named List Element. */
/* Returns the first partially matching tag found. */
/* Pattern is a symbol. */
The rest of the summary set (mean, min, max, prod) and also do_logic3 
(all, any) call matchArg and so have the same problem.

I can see there could be a discussion about whether or not this is
a bug, but I think all will agree that it's a might peculiar.
I don't see how there can be discussion: it breaks the stated rules for 
argument matching.

This is done in 2.0.1 but the same behavior is in 1.8.1.
version
   _ platform i386-pc-mingw32
arch i386  os   mingw32   system   i386, mingw32 status 
major2 minor0.1   year 2004  month 
11day  15language R 

Patrick Burns
Burns Statistics
[EMAIL PROTECTED]
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")
__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

--
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595
__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] Re: Method dispatch S3/S4 through optimize()

2004-11-20 Thread Roger Bivand
After looking at this with Roger Koenker off-list, the problem can be 
replicated running R CMD check tryout on:

http://reclus.nhh.no/R/Devel/tryout_0.1-1.tar.gz

With a NAMESPACE file in tryout, the S4 dispatch breaks down for det(), 
without a NAMESPACE file, it runs without error (on R-devel with SparseM 
0.52 for me). Roger pointed me to 

http://tolstoy.newcastle.edu.au/R/devel/04a/0042.html

which looks similar, but was said to be resolved. A practical but too 
invasive correction is to change the SparseM code to:

setGeneric("Det", function(x, ...) standardGeneric("Det"))
setMethod("Det","matrix",get("det", pos=NULL, mode= "function"))
setMethod("Det","matrix.csr", function(x, ...) Det(chol(x))^2)
setMethod("Det","matrix.csr.chol", function(x, ...) [EMAIL PROTECTED])

rather than original below, the alternative is to drop NAMESPACE in 
spdep, which is not desirable either. 

Roger


On Fri, 19 Nov 2004, Roger Bivand wrote:

> On Thu, 18 Nov 2004, roger koenker wrote:
> 
> > I am far from an expert on S4 method dispatch, so at the risk of
> > embarrassing myself I will just indicate how the det() function is
> > written in SparseM now in the hope that someone else will see the source
> > of the problem:
> > 
> > setGeneric("det")
> > setMethod("det","matrix",get("det", pos=NULL, mode= "function"))
> > setMethod("det","matrix.csr", function(x, ...) det(chol(x))^2)
> > setMethod("det","matrix.csr.chol", function(x, ...) [EMAIL PROTECTED])
> > 
> > The Cholesky function chol in SparseM was recently extended slightly to
> > compute this determinant as an additional component, so if the argument
> > is already of the matrix.csr.chol class det() just extracts this
> > component, otherwise it tries to do the cholesky, or defaults to the
> > base function.
> 
> As I read the SparseM code, it is following the specification, and if
> there was something wrong, the simple example 1) would not have worked
> either. But it does, so something changes in the context of where a
> function like det() and chol() is called from, here through optimize(),
> that sends it to the wrong place based on assuming that the class is 
> unknown. 
> 
> I'll try to make an example that doesn't depend on spdep, just on SparseM 
> and optimize().
> 
> This is frustrating, because with Ord's trick of using matrices similar to
> symmetric, the SparseM route will be very useful for most situations, 
> even though it requires strictly symmetric matrices. So your provision of 
> det() for "matrix.csr" is very useful, once we sort out this strange 
> behaviour.
> 
> Roger
> 
> > 
> > I hope that this might expose some fly in the soup.
> > 
> > 
> > url:www.econ.uiuc.edu/~rogerRoger Koenker
> > email   [EMAIL PROTECTED]   Department of Economics
> > vox:217-333-4558University of Illinois
> > fax:217-244-6678Champaign, IL 61820
> > 
> > On Nov 18, 2004, at 3:34 PM, Roger Bivand wrote:
> > 
> > > I have been running into difficulties with dispatching on an S4 class
> > > defined in the SparseM package, when the method calls are inside a
> > > function passed as the f= argument to optimize() in functions in the 
> > > spdep
> > > package. The S4 methods are typically defined as:
> > >
> > > setMethod("det","matrix.csr", function(x, ...) det(chol(x))^2)
> > >
> > > that is within setMethod() rather than by name before the setMethod().
> > >
> > > When called from within functions passed as the f= argument to 
> > > optimize,
> > > the S3 generics for det() and chol() get picked up, not the S4 generics
> > > for the S4 SparseM classes. This looks for instance like (from
> > > example(boston)):
> > >
> > >> gp2 <- lagsarlm(log(CMEDV) ~ CRIM + ZN + INDUS + CHAS + I(NOX^2) + 
> > >> I(RM^2)
> > > +  +  AGE + log(DIS) + log(RAD) + TAX + PTRATIO + B + log(LSTAT),
> > > +  data=boston.c, nb2listw(boston.soi), method="SparseM")
> > > matrix.csr
> > > Error in chol(tmp1) : non-numeric argument to chol
> > >
> > > (this is the error message in chol.R in base). tmp1 is of class
> > > "matrix.csr", but is being sent to the S3 class (error in function
> > > sar.lag.mix.f.sM() in R/lag.spsarlm.R).
> > >
> > > sar.lag.mix.f.sM <- function(rho, W, e.a, e.b, e.c, n, quiet)
> > > {
> > >   SSE <- e.a - 2*rho*e.b + rho*rho*e.c
> > >   s2 <- SSE/n
> > >   tmp1 <- asMatrixCsrIrW(W, rho)
> > > cat(class(tmp1), "\n")
> > >   tmp2 <- chol(tmp1)
> > > # tmp2 <- .cholMatrixCsr(tmp1)
> > > cat(class(tmp2), "\n")
> > >   tmp3 <- ([EMAIL PROTECTED])^2
> > > cat(tmp3, "\n")
> > >   ret <- (log(tmp3)
> > >   - ((n/2)*log(2*pi)) - (n/2)*log(s2) - (1/(2*s2))*SSE)
> > >   if (!quiet)
> > >   cat("(SparseM) rho:\t", rho, "\tfunction value:\t", ret, "\n")
> > >   ret
> > > }
> > >
> > >
> > > Three further observations:
> > >
> > > 1) In a simpler case:
> > >
> > >> library(spdep)
> > > Loading required package: tripack
> > > Loading required packag

[Rd] sum and partial argument name matching

2004-11-20 Thread Patrick Burns
"sum" (and  perhaps  other functions?) allows partial argument
name matching after its three-dots argument:
> sum(1:4, NA, n=78, na.rm=FALSE)
[1] 10
> sum(1:4, NA, n=78, na.rm=TRUE)
[1] 11
I can see there could be a discussion about whether or not this is
a bug, but I think all will agree that it's a might peculiar.
This is done in 2.0.1 but the same behavior is in 1.8.1.
> version
_ 
platform i386-pc-mingw32
arch i386  
os   mingw32   
system   i386, mingw32 
status 
major2 
minor0.1   
year 2004  
month11
day  15
language R  


Patrick Burns
Burns Statistics
[EMAIL PROTECTED]
+44 (0)20 8525 0696
http://www.burns-stat.com
(home of S Poetry and "A Guide for the Unwilling S User")
__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel


Re: [Rd] whishlist: legend - changing color of the boxes-border

2004-11-20 Thread Uwe Ligges
Wolski wrote:
Hi,
Drawing a legend I would like to be able to specify the color of boxes which 
are drawn if fill or density is specified.
eg.
legend(0,4,c("raw","LR/PR-TPS"),fill=c(1,2),col=c(1,2),density=c(20,20),angle=c(-20,45),bty="n")
Currently the color of the boxes -- border is always black and can *not* be 
changed. To get this option only a *minimal* change is required.
Please consider the following code snipped copied from the function legend 
(package graphics).
The sensible line is marked by ###<-
 if (mfill) {
if (plot) {
fill <- rep(fill, length.out = n.leg)
rect2(left = xt, top = yt + ybox/2, dx = xbox, dy = ybox, 
col = fill, density = density, angle = angle, 
border = "black")  <--
}
xt <- xt + dx.fill
}

Changing this line from 

border="black"
to 

border=col.
Will enable to specify the color of the boxes borders.
If specifying the colors by param _fill_ the parameter _col_ is not used anyway 
but still available and set already to black in the parameter declaration. 
Therefore why not use it to specify colors to borders of boxes?
No! You want to specify "col" rather than "fill" in the following example:
  plot(1:10)
  legend(3,3, c("Hello", "World"), pch=1:2, fill=c("red", "black"))
But what you can easily do to change the box color is:
  plot(1:10)
  opar <- par(fg="blue")
  legend(3, 3, "Hello World", pch=20, col="red", text.col="green")
  par(opar)
Uwe Ligges


Yours
/E


Dipl. bio-chem. Eryk Witold Wolski @MPI-Moleculare Genetic   
Ihnestrasse 63-73 14195 Berlin'v'
tel: 0049-30-83875219/   \   
mail: [EMAIL PROTECTED]---W-W
http://r4proteomics.sourceforg.net

__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel