Dan Davison
2008-Dec-09 00:45 UTC
[Rd] repeat bug report: as.factor argument to row / col fails if NULL dimnames
This bug was reported to r-devel by Martin Morgan on 13th May 2008 (original email pasted below). However I couldn't locate it in the bug tracker (with searches for row, col, as\.factor) It is still present in today's svn version (rev 47115). I hope I'm doing something useful by bringing it up again. I have not sent this to r-bugs, as I'm concerned that not locating it in the bug tracker could be my failing. Dan original report: ------------------------------------------------------------------ col(matrix(0, 5, 5), as.factor=TRUE) fails> col(matrix(0, 5, 5), as.factor=TRUE)Error in factor(.Internal(col(dim(x))), labels = colnames(x)) : invalid labels; length 0 should be 1 or 5 when the matrix has no dimnames. This is not as advertised. I would have expected the equivalent of factor(.Internal(col(dim(x))), labels=colnames(x, do.NULL=FALSE, prefix=""))> sessionInfo()R version 2.8.0 Under development (unstable) (2008-05-13 r45682) x86_64-unknown-linux-gnu Martin -- Martin Morgan Computational Biology / Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: Arnold Building M2 B169 Phone: (206) 667-2793 ------------------------------------------------------------------ -- http://www.stats.ox.ac.uk/~davison
Prof Brian Ripley
2008-Dec-12 09:08 UTC
[Rd] repeat bug report: as.factor argument to row / col fails if NULL dimnames
I have never seen the report in the repository. There were problems with
R-bugs at around that time (most email submission was stalled for a month
or so).
However, I think the problems are far more serious: the help page says
Returns a matrix of integers indicating their column number in a
matrix-like object.
...
as.factor: a logical value indicating whether the value should be
returned as a factor rather than as numeric.
Value:
An integer matrix with the same dimensions as 'x' and whose
'ij'-th element is equal to 'j'.
There is no mention of using the column labels as the values and the
result was not even a matrix. I certainly expected the factor levels to
be numeric.
I presume that the intention is to use the column labels (default
seq_len(nrow(x)) ) in place of the numbers, and to return a factor matrix,
so I have implemented that for col() and row().
However, I do wonder that anyone was using as.factor=TRUE given that it
did not do anything like what it was documented to.
On Mon, 8 Dec 2008, Dan Davison wrote:
> This bug was reported to r-devel by Martin Morgan on 13th May 2008
> (original email pasted below). However I couldn't locate it in the bug
> tracker (with searches for row, col, as\.factor) It is still present
> in today's svn version (rev 47115). I hope I'm doing something
useful
> by bringing it up again. I have not sent this to r-bugs, as I'm
> concerned that not locating it in the bug tracker could be my failing.
>
> Dan
>
> original report:
> ------------------------------------------------------------------
> col(matrix(0, 5, 5), as.factor=TRUE) fails
>
>> col(matrix(0, 5, 5), as.factor=TRUE)
> Error in factor(.Internal(col(dim(x))), labels = colnames(x)) :
> invalid labels; length 0 should be 1 or 5
>
> when the matrix has no dimnames. This is not as advertised. I would
> have expected the equivalent of
>
> factor(.Internal(col(dim(x))),
> labels=colnames(x, do.NULL=FALSE, prefix=""))
>
>> sessionInfo()
> R version 2.8.0 Under development (unstable) (2008-05-13 r45682)
> x86_64-unknown-linux-gnu
>
> Martin
> --
> Martin Morgan
> Computational Biology / Fred Hutchinson Cancer Research Center
> 1100 Fairview Ave. N.
> PO Box 19024 Seattle, WA 98109
>
> Location: Arnold Building M2 B169
> Phone: (206) 667-2793
> ------------------------------------------------------------------
>
>
> --
> http://www.stats.ox.ac.uk/~davison
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
--
Brian D. Ripley, ripley at 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 272866 (PA)
Oxford OX1 3TG, UK Fax: +44 1865 272595
Apparently Analagous Threads
- write.table with row.names=FALSE unnecessarily slow?
- [wishlist, patch] make row() and col() preserve dimnames (PR#13705)
- unlink fails to remove symbolic links
- X11 image problem in R-2.8.0 Under development / R-2.7
- more efficient small subsets from moderate vectors?