diff --git a/R/transpose.R b/R/transpose.R index a7b2afc84..684b135d4 100644 --- a/R/transpose.R +++ b/R/transpose.R @@ -1,4 +1,4 @@ -transpose = function(l, fill=NA, ignore.empty=FALSE, keep.names=NULL, make.names=NULL, return.list=FALSE) { +transpose = function(l, fill=NA, ignore.empty=FALSE, keep.names=NULL, make.names=NULL, list.cols=FALSE) { if (!is.null(make.names)) { stopifnot(length(make.names)==1L) if (is.character(make.names)) { @@ -14,14 +14,12 @@ transpose = function(l, fill=NA, ignore.empty=FALSE, keep.names=NULL, make.names colnames = as.character(l[[make.names]]) l = if (is.data.table(l)) l[,-make.names,with=FALSE] else l[-make.names] } - ans = .Call(Ctranspose, l, fill, ignore.empty, keep.names, return.list) + ans = .Call(Ctranspose, l, fill, ignore.empty, keep.names, list.cols) if (!is.null(make.names)) setattr(ans, "names", c(keep.names, colnames)) else if (is.data.frame(l)) # including data.table but not plain list setattr(ans, "names", c(keep.names, paste0("V", seq_len(length(ans)-length(keep.names))))) - if (!return.list) { - if (is.data.table(l)) setDT(ans) - else if (is.data.frame(l)) setDF(ans) - } + if (is.data.table(l)) setDT(ans) + else if (is.data.frame(l)) setDF(ans) ans[] } diff --git a/src/transpose.c b/src/transpose.c index 6d9c9e19c..36ef13e65 100644 --- a/src/transpose.c +++ b/src/transpose.c @@ -2,7 +2,7 @@ #include #include -SEXP transpose(SEXP l, SEXP fill, SEXP ignoreArg, SEXP keepNamesArg, SEXP returnListArg) { +SEXP transpose(SEXP l, SEXP fill, SEXP ignoreArg, SEXP keepNamesArg, SEXP listColsArg) { int nprotect=0; if (!isNewList(l)) @@ -18,9 +18,9 @@ SEXP transpose(SEXP l, SEXP fill, SEXP ignoreArg, SEXP keepNamesArg, SEXP return if (length(fill) != 1) error(_("fill must be a length 1 vector, such as the default NA")); R_len_t ln = LENGTH(l); - if (!isLogical(returnListArg) || LOGICAL(returnListArg)[0]==NA_LOGICAL) - error(_("ignore.empty should be logical TRUE/FALSE.")); - bool returnList = LOGICAL(returnListArg)[0]; + if (!isLogical(listColsArg) || LOGICAL(listColsArg)[0]==NA_LOGICAL) + error(_("list.cols should be logical TRUE/FALSE.")); + bool listCol = LOGICAL(listColsArg)[0]; // preprocessing int maxlen=0, zerolen=0; @@ -36,7 +36,7 @@ SEXP transpose(SEXP l, SEXP fill, SEXP ignoreArg, SEXP keepNamesArg, SEXP return if (isFactor(li)) type=STRSXP; if (type>maxtype) maxtype=type; } - if (returnList) maxtype=VECSXP; // need to keep preprocessing for zerolen + if (listCol) maxtype=VECSXP; // need to keep preprocessing for zerolen fill = PROTECT(coerceVector(fill, maxtype)); nprotect++; SEXP ans = PROTECT(allocVector(VECSXP, maxlen+rn)); nprotect++;