[Rd] Unfixed bugs in latest R-patched

Radford Neal radford at cs.toronto.edu
Tue Jun 24 22:40:30 CEST 2014


>     > o Fixed the following bug (also present in R-2.15.0 and R-3.0.2):
>       
>     > x <- t(5)
>     > print (x %*% c(3,4))
>     > print (crossprod(5,c(3,4)))
> 
>     > The call of crossprod produced an error, whereas the
>     > corresponding use of %*% does not.
> 
>     > o Fixed the following bug (also present in R-2.15.0 and R-3.0.2):
>       
>     > v <- c(1,2)
>     > m <- matrix(c(3,4),1,2)
>     > print(t(m)%*%v)
>     > print(crossprod(m,v))
> 
>     > in which crossprod gave an error rather than produce the answer
>     > for the corresponding use of %*%.

> As S and R's terminology has always been mathematically correct and
> "knows" that a vector is not a 1-row matrix or 1-column matrix 
> (which some people call row-vector and column-vector), R has
> indeed much more freedom to be lenient in how to promote vectors
> to matrices, and it has always done so tolerantly for some cases
> of "%*%", but even there is room for discussion, see below.

> However, one can argue that the current behavior is quite
> consistent {there is more than one kind of consistency here; in
> this case it's the consistency of underlying C code IIRC}, and
> not strictly a bug.

If you look at help(crossprod), you'll see that it says that
crossprod(x,y) is equivalent to t(x) %*% y.  But it's not, since
the latter works in some cases where the former gives an error.
So it's a bug.

Furthermore, crossprod(x,y) ought to be equivalent to t(x) %*% y,
even in cases where a vector needs to get promoted to a matrix,
because such cases can arise from inadvertant dropping of dimensions
when subscriptiong a matrix (eg, with 1:n, with n happening to be 1).
Sometimes, this problem gets fixed by the transpose.  

   Radford Neal



More information about the R-devel mailing list