Skip to content

Commit

Permalink
add man
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-schwen committed Dec 7, 2023
1 parent 442839e commit 8cdc7d8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions man/transpose.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ transpose(l, fill=NA, ignore.empty=FALSE, keep.names=NULL, make.names=NULL)
\item{ignore.empty}{Default is \code{FALSE}. \code{TRUE} will ignore length-0 list elements.}
\item{keep.names}{The name of the first column in the result containing the names of the input; e.g. \code{keep.names="rn"}. By default \code{NULL} and the names of the input are discarded.}
\item{make.names}{The name or number of a column in the input to use as names of the output; e.g. \code{make.names="rn"}. By default \code{NULL} and default names are given to the output columns.}
\item{list.cols}{Default is \code{FALSE}. \code{TRUE} will avoid promoting types and return columns of type \code{list} instead.}
}
\details{
The list elements (or columns of \code{data.frame}/\code{data.table}) should be all \code{atomic}. If list elements are of unequal lengths, the value provided in \code{fill} will be used so that the resulting list always has all elements of identical lengths. The class of input object is also preserved in the transposed result.
Expand All @@ -35,6 +36,9 @@ setDT(transpose(ll, fill=0))[]

DT = data.table(x=1:5, y=6:10)
transpose(DT)

DT = data.table(x=1:3, y=c("a","b","c"))
transpose(DT, list.cols=TRUE)
}
\seealso{
\code{\link{data.table}}, \code{\link{tstrsplit}}
Expand Down
4 changes: 2 additions & 2 deletions src/transpose.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ SEXP transpose(SEXP l, SEXP fill, SEXP ignoreArg, SEXP keepNamesArg, SEXP listCo
SEXPTYPE maxtype=0;
for (int i=0; i<ln; ++i) {
SEXP li = VECTOR_ELT(l, i);
if (!isVectorAtomic(li) && !isNull(li))
error(_("Item %d of list input is not an atomic vector"), i+1);
if (!isVectorAtomic(li) && !isNull(li) && !isNewList(li))
error(_("Item %d of list input is not either an atomic vector, or a list"), i+1);
const int len = length(li);
if (len>maxlen) maxlen=len;
zerolen += (len==0);
Expand Down

0 comments on commit 8cdc7d8

Please sign in to comment.