[Rd] several bugs (PR#918) lists and matrices

ripley@stats.ox.ac.uk ripley@stats.ox.ac.uk
Wed, 13 Mar 2002 08:56:22 +0100 (MET)


Points 1 and 2 are already fixed in R-devel, as I did indicate on R-help,
yesterday.

Point 3 is in the FAQ, no less:

   * In R, if `x' is a list, then `x[i] <- NULL' and `x[[i]] <- NULL'
     remove the specified elements from `x'.  The first of these is
     incompatible with S, where it is a no-op.  (Note that you can set
     elements to `NULL' using `x[i] <- list(NULL)'.)

Please don't mix up unrelated reports: point 3 has nothing to do with
matrix lists.


On Wed, 13 Mar 2002 rmh@surfer.sbm.temple.edu wrote:

> ### I got bit again by the same bugs I wrote about a year ago.
> ### The bugs are related to matrices and arrays of lists.
>
> ### 1. There is a clear inconsistency in how R handles two
> ### functionally equivalent statements.
> ### array() is able to take a list and create a matrix.
> ### matrix() is unable to create that matrix.
>
>
> > vector("list", 2)
> [[1]]
> NULL
>
> [[2]]
> NULL
>
> > array(vector("list", 2), dim=c(2,1))
>      [,1]
> [1,] "NULL"
> [2,] "NULL"
> > tmpa <- array(vector("list", 2), dim=c(2,1))
> > class(tmpa)
> NULL
> > is.array(tmpa)
> [1] TRUE
> > is.matrix(tmpa)
> [1] TRUE
> > tmpm <- matrix(vector("list", 2), nrow=2)
> Error in matrix(vector("list", 2), nrow = 2) :
> 	Unimplemented feature in copyVector
> >
>
>
>
>
> ### 2. Here the matrix single-[ subscript is doing the wrong thing,
> ### without giving a warning.
>
> > tmp <- array(vector("list", 2), 1:2)
> > tmp
>      [,1]   [,2]
> [1,] "NULL" "NULL"
> > tmp[1]
> [[1]]
> NULL
>
> > tmp[[1]]
> NULL
> > tmp[1,1]
> [[1]]
> NULL
>
> > tmp[[1,1]]
> NULL
> > list("abc")
> [[1]]
> [1] "abc"
>
> > tmp[1] <- list("abc")  ## assignment
> > tmp[1]
> [[1]]
> [1] "abc"
>
> > tmp[[1]]
> [1] "abc"
> > tmp[1,1]     ## incorrect retrieval
> [[1]]
> NULL
>
> > tmp[[1,1]]
> [1] "abc"
>
> > tmp[1,2] <- list("def")  ## refuse to do similar assignment
> Error: incompatible types in subset assignment
> >
>
>
>
> ### 3. subsetting a vector of lists doesn't behave the way I anticipate.
> ### It looks like NULL is not handled consistently inside a vector.
> ### Sometimes it can be an element, sometimes not.
>
> > tmpv <- vector("list", 2)
> > tmpv
> [[1]]
> NULL
>
> [[2]]
> NULL
>
> > tmpv[1] <- "abcd"  ## I assigned to the first element.
> > tmpv               ## Both elements are still here.
> [[1]]
> [1] "abcd"
>
> [[2]]
> NULL
>
> > tmpv[1] <- NULL    ## I assigned to the first element.
> > tmpv               ## The second element is gone.
> [[1]]
> NULL
>
> >
>
>
>
> ### This time the issue came up in an attempt to make abind work with R.
> ### abind() is a generalization of rbind and cbind to arrays.
> ### Tony Plate and I posted it to StatLib in 1996
> ### (http://lib.stat.cmu.edu/S/abind).
>
> ### I would like you to consider adding abind to R.
> ### The posted abind doesn't work in R, for the reasons above and due to
> ### a difference in behavior of match.call between S -Plusand R that I am
> ### reporting in a separate bug report.
> ### There are two revised files, currently available at
> ### http://surfer.sbm.temple.edu/~rmh/abind.r
> ### http://surfer.sbm.temple.edu/~rmh/abind.test.in.r
> ### The documentation in statlib applies to these files.
> ### I will update the statlib version after I understand why R differs.
>
> > version
>          _
> platform i386-pc-mingw32
> arch     x86
> os       Win32
> system   x86, Win32
> status
> major    1
> minor    4.1
> year     2002
> month    01
> day      30
> language R
> >
>
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
>

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
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 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._