From josh.m.ulrich at gmail.com  Sat Jan 21 18:58:18 2017
From: josh.m.ulrich at gmail.com (Joshua Ulrich)
Date: Sat, 21 Jan 2017 11:58:18 -0600
Subject: [Rd] bug in rbind?
In-Reply-To: <D1E6227CBC482446B2D877554FCD338C2CCB4982@MBX01A.stf.nus.edu.sg>
References: <D1E6227CBC482446B2D877554FCD338C2CCB4982@MBX01A.stf.nus.edu.sg>
Message-ID: <CAPPM_gRThYFANgAwxb-9fa4=X4qRE80gH3SGESnxWEe-DzVRqg@mail.gmail.com>

I'm not sure whether or not this is a bug, but I did isolate the line
where the error is thrown:
src/library/base/R/dataframe.R:1395.
https://github.com/wch/r-source/blob/01374c3c367fa12f555fd354f735a6e16e5bd98e/src/library/base/R/dataframe.R#L1395

The error is thrown because the line attempts to set a subset of the
rownames to NULL, which fails.

R> options(error = recover)
R> rbind(dfm.names, dfm)
Error in rownames(value[[jj]])[ri] <- rownames(xij) :
  replacement has length zero

Enter a frame number, or 0 to exit

1: rbind(dfm.names, dfm)
2: rbind(deparse.level, ...)

Selection: 2
Called from: top level
Browse[1]> rownames(value[[jj]])
[1] "a" "b" "c" NA  NA  NA
Browse[1]> rownames(xij)
NULL
Browse[1]> ri
[1] 4 5 6
Browse[1]> rownames(value[[jj]])[ri]
[1] NA NA NA


On Mon, Jan 16, 2017 at 7:50 PM, Krzysztof Banas <krzysztof at nus.edu.sg> wrote:
> I suspect there may be a bug in base::rbind.data.frame
>
> Below there is minimal example of the problem:
>
> m <- matrix (1:12, 3)
> dfm <- data.frame (c = 1 : 3, m = I (m))
> str (dfm)
>
> m.names <- m
> rownames (m.names) <- letters [1:3]
> dfm.names <- data.frame (c = 1 : 3, m = I (m.names))
> str (dfm.names)
>
> rbind (m, m.names)
> rbind (m.names, m)
> rbind (dfm, dfm.names)
>
> #not working
> rbind (dfm.names, dfm)
>
> Error in rbind(deparse.level, ...) : replacement has length zero
>
> rbind (dfm, dfm.names)$m
>
>
>      [,1] [,2] [,3] [,4]
>
> <NA>    1    4    7   10
>
> <NA>    2    5    8   11
>
> <NA>    3    6    9   12
>
> a       1    4    7   10
>
> b       2    5    8   11
>
> c       3    6    9   12
>
>
>
> ________________________________
>
> Important: This email is confidential and may be privileged. If you are not the intended recipient, please delete it and notify us immediately; you should not copy or use it for any purpose, nor disclose its contents to any other person. Thank you.
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



-- 
Joshua Ulrich  |  about.me/joshuaulrich
FOSS Trading  |  www.fosstrading.com
R/Finance 2016 | www.rinfinance.com



[Rd] bug in rbind?
Joshua Ulrich