Skip to content

Commit

Permalink
Don't prefix with "V" on auto generating idcol, #591.
Browse files Browse the repository at this point in the history
  • Loading branch information
arunsrinivasan committed Jan 25, 2015
1 parent 1633d0e commit f4a06eb
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion R/data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -2270,7 +2270,7 @@ rbindlist <- function(l, use.names=fill, fill=FALSE, idcol=NULL) {
len = vapply(l, NROW, 0L)
idx = which(len > 0L)
len = len[idx]
if (is.null(nm)) nm = paste("V", seq_along(len), sep="")
if (is.null(nm)) nm = as.character(seq_along(len))
else nm = nm[idx]
ansnames = c(idcol, names(ans))
set(ans, j=idcol, value=rep.int(nm, len))
Expand Down
2 changes: 1 addition & 1 deletion inst/tests/tests.Rraw
Original file line number Diff line number Diff line change
Expand Up @@ -5464,7 +5464,7 @@ DT3 = data.table(A = factor(INT(7:8)), C = 0)
ans = data.table(A=factor(INT(7,8,7,8,7,1,2,1,2,1,7,8), levels=c("7", "8", "1", "2")), B=factor(INT(6:10, rep(NA,7))), C=0, D=ordered(INT(rep(NA,5), 1:5, rep(NA,2))))
test(1393.1, rbindlist(list(DT1, DT2, DT3), fill = TRUE), ans)
# test for #591 (R-Forge #2491)
ans[, ID := rep(c("V1", "V2", "V3"), c(5,5,2))]
ans[, ID := rep(as.character(1:3), c(5,5,2))]
setcolorder(ans, c("ID", LETTERS[1:4]))
test(1393.2, rbindlist(list(DT1, DT2, DT3), fill = TRUE, idcol="ID"), ans)

Expand Down
2 changes: 1 addition & 1 deletion man/rbindlist.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ rbindlist(l, use.names=fill, fill=FALSE, idcol=NULL)
\item{l}{ A list containing \code{data.table}, \code{data.frame} or \code{list} objects. At least one of the inputs should have column names set. \code{\dots} is the same but you pass the objects by name separately. }
\item{use.names}{If \code{TRUE} items will be bound by matching column names. By default \code{FALSE} for \code{rbindlist} (for backwards compatibility) and \code{TRUE} for \code{rbind} (consistency with base). Columns with duplicate names are bound in the order of occurrence, similar to base. When TRUE, at least one item of the input list has to have non-null column names.}
\item{fill}{If \code{TRUE} fills missing columns with NAs. By default \code{FALSE}. When \code{TRUE}, \code{use.names} has to be \code{TRUE}, and all items of the input list has to have non-null column names. }
\item{idcol}{Should an index column be generated? Default (\code{NULL}) is not to. \code{TRUE} auto names the column to \code{.id}. Alternatively it also accepts a character vector of length-1 for the index column name. See \code{examples}.}
\item{idcol}{Generates an index column of \code{character} type. Default (\code{NULL}) is not to. If \code{idcol=TRUE} then the column is auto named \code{.id}. Alternatively the column name can be directly provided to \code{idcol}. See \code{examples}.}
}
\details{
Each item of \code{l} can be a \code{data.table}, \code{data.frame} or \code{list}, including \code{NULL} (skipped) or an empty object (0 rows). \code{rbindlist} is most useful when there are a variable number of (potentially many) objects to stack, such as returned by \code{lapply(fileNames, fread)}. \code{rbind} however is most useful to stack two or three objects which you know in advance. \code{\dots} should contain at least one \code{data.table} for \code{rbind(...)} to call the fast method and return a \code{data.table}, whereas \code{rbindlist(l)} always returns a \code{data.table} even when stacking a plain \code{list} with a \code{data.frame}, for example.
Expand Down

0 comments on commit f4a06eb

Please sign in to comment.