R-alpha: Problems with dimnames and names
Martyn Plummer
plummer@iarc.fr
Fri, 28 Nov 1997 12:05:22 +0100 (MET)
This message is in MIME format
--_=XFMail.1.1.p0.Linux:971128122615:3052=_
Content-Type: text/plain; charset=us-ascii
I have rounded up three buglets in R-0.50-a4. Two of them I can
fix and a patch is supplied below. I hope this is useful for the
current source (if these haven't been fixed already :)
1) cov
cov() fails when it's argument is a matrix with one column and with
column names defined. It tries to apply dimnames to the output but
the output is a vector of length 1.
> x <- matrix(rnorm(100),ncol=1,dimnames=list(NULL,"foo"))
> var(x)
Error: dimnames applied to non-array
2) Subscripting one-dimensional arrays.
These are treated as vectors when subscripting
so subscripting by dimnames fails.
> x <- c(0,0,0,1,1,1,1,3)
> table(x)
0 1 3
3 4 1
> table(x)["3"]
Error: subscript out of bounds
3) I have no idea what's going on here.
> c(r=1,s=2)
s
2
> c(u=100,b=4)
b
4
This seems to happen only for "r" and "u". Other single-letter
names are OK. This doesn't happen on my home PC which is still
running R-0.50-a1.
Martyn
--_=XFMail.1.1.p0.Linux:971128122615:3052=_
Content-Type: text/plain; charset=us-ascii; name=apatch; SizeOnDisk=1206
Content-Description: apatch
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="apatch"
diff -ur R-0.50-a4/src/main/cov.c R-0.50-a4.patched/src/main/cov.c
--- R-0.50-a4/src/main/cov.c Sun Nov 24 23:43:05 1996
+++ R-0.50-a4.patched/src/main/cov.c Fri Nov 28 11:21:23 1997
@@ -390,7 +390,7 @@
}
if(isNull(y)) {
x = getAttrib(x, R_DimNamesSymbol);
- if(!isNull(x) && !isNull(CADR(x))) {
+ if(ncx > 1 && !isNull(x) && !isNull(CADR(x))) {
PROTECT(ind = allocList(2));
CAR(ind) = CADR(x);
CADR(ind) = CADR(x);
@@ -401,7 +401,7 @@
else {
x = getAttrib(x, R_DimNamesSymbol);
y = getAttrib(y, R_DimNamesSymbol);
- if((!isNull(x) && !isNull(CADR(x))) || (!isNull(y) && !isNull(CADR(y)))) {
+ if((ncx > 1 && !isNull(x) && !isNull(CADR(x))) || ( ncy > 1 && !isNull(y) &&
!isNull(CADR(y)))) {
PROTECT(ind = allocList(2));
CAR(ind) = CADR(x);
CADR(ind) = CADR(y);
diff -ur R-0.50-a4/src/main/subset.c R-0.50-a4.patched/src/main/subset.c
--- R-0.50-a4/src/main/subset.c Mon Aug 11 04:59:12 1997
+++ R-0.50-a4.patched/src/main/subset.c Fri Nov 28 11:16:55 1997
@@ -608,7 +608,7 @@
PROTECT(dim = getAttrib(x, R_DimSymbol));
nsubs = length(subs);
- if(nsubs == 1) {
+ if(nsubs == 1 && isNull(dim)) {
ans = vectorSubset(x, CAR(subs), call);
}
else {
--_=XFMail.1.1.p0.Linux:971128122615:3052=_--
End of MIME message
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._