Skip to content

Commit fae047b

Browse files
committed
man entry on setorder.Rd
1 parent bc3a413 commit fae047b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

man/setorder.Rd

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
\alias{fastorder}
66
\alias{forder}
77
\alias{forderv}
8+
\alias{sort_by}
89

910
\title{Fast row reordering of a data.table by reference}
1011
\description{
@@ -32,6 +33,7 @@ setorderv(x, cols = colnames(x), order=1L, na.last=FALSE)
3233
# optimised to use data.table's internal fast order
3334
# x[order(., na.last=TRUE)]
3435
# x[order(., decreasing=TRUE)]
36+
# sort_by(x, ., na.last=TRUE, decreasing=FALSE)
3537
}
3638
\arguments{
3739
\item{x}{ A \code{data.table}. }
@@ -46,7 +48,7 @@ when \code{b} is of type \code{character} as well. }
4648
\code{order} must be either \code{1} or equal to that of \code{cols}. If
4749
\code{length(order) == 1}, it is recycled to \code{length(cols)}. }
4850
\item{na.last}{ \code{logical}. If \code{TRUE}, missing values in the data are placed last; if \code{FALSE}, they are placed first; if \code{NA} they are removed.
49-
\code{na.last=NA} is valid only for \code{x[order(., na.last)]} and its
51+
\code{na.last=NA} is valid only for \code{x[order(., na.last)]} and related \code{sort_by(x, .)} and its
5052
default is \code{TRUE}. \code{setorder} and \code{setorderv} only accept
5153
\code{TRUE}/\code{FALSE} with default \code{FALSE}. }
5254
}
@@ -71,8 +73,8 @@ sets the \code{sorted} attribute.
7173

7274
\code{na.last} argument, by default, is \code{FALSE} for \code{setorder} and
7375
\code{setorderv} to be consistent with \code{data.table}'s \code{setkey} and
74-
is \code{TRUE} for \code{x[order(.)]} to be consistent with \code{base::order}.
75-
Only \code{x[order(.)]} can have \code{na.last = NA} as it is a subset operation
76+
is \code{TRUE} for \code{x[order(.)]} and \code{sort_by(x, .)} to be consistent with \code{base::order}.
77+
Only \code{x[order(.)]} (and related \code{sort_by(x, .)}) can have \code{na.last = NA} as it is a subset operation
7678
as opposed to \code{setorder} or \code{setorderv} which reorders the data.table
7779
by reference.
7880
@@ -96,6 +98,11 @@ was started in. By contrast, \code{"america" < "BRAZIL"} is always \code{FALSE}
9698
9799
If \code{setorder} results in reordering of the rows of a keyed \code{data.table},
98100
then its key will be set to \code{NULL}.
101+
102+
\code{sort_by(x, y, \dots)} is the S3 method for the generic \code{sort_by} for \code{data.table}'s.
103+
It uses the same formula or list interfaces as data.frame's \code{sort_by} but internally uses \code{data.table}'s fast ordering,
104+
hence it behaves the same as \code{x[order(.)]} and takes the same optional named arguments and their defaults.
105+
99106
}
100107
\value{
101108
The input is modified by reference, and returned (invisibly) so it can be used

0 commit comments

Comments
 (0)