Skip to content

Commit 4899b39

Browse files
document essential complexity of setDT (#6756)
1 parent 44a87a8 commit 4899b39

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

man/setDT.Rd

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,25 @@ setDT(x, keep.rownames=FALSE, key=NULL, check.names=FALSE)
1818
}
1919
2020
\details{
21-
When working on large \code{lists} or \code{data.frames}, it might be both time and memory consuming to convert them to a \code{data.table} using \code{as.data.table(.)}, as this will make a complete copy of the input object before to convert it to a \code{data.table}. The \code{setDT} function takes care of this issue by allowing to convert \code{lists} - both named and unnamed lists and \code{data.frames} \emph{by reference} instead. That is, the input object is modified in place, no copy is being made.
21+
When working on large \code{list}s or \code{data.frame}s, it might be both time- and memory-consuming to convert them to a \code{data.table} using \code{as.data.table(.)}, which will make a complete copy of the input object before converting it to a \code{data.table}. \code{setDT} takes care of this issue by converting any \code{list} (named or unnamed, data.frame or not) \emph{by reference} instead. That is, the input object is modified in place with no copy.
22+
23+
This should come with low overhead, but note that \code{setDT} does check that the input is valid by looking for inconsistent input lengths and inadmissible column types (e.g. matrix).
2224
}
2325
2426
\value{
25-
The input is modified by reference, and returned (invisibly) so it can be used in compound statements; e.g., \code{setDT(X)[, sum(B), by=A]}. If you require a copy, take a copy first (using \code{DT2 = copy(DT)}). See \code{?copy}.
27+
The input is modified by reference, and returned (invisibly) so it can be used in compound statements; e.g., \code{setDT(X)[, sum(B), by=A]}. If you require a copy, take a copy first (using \code{DT2 = copy(DT)}). See \code{?copy}.
2628
}
2729
28-
\seealso{ \code{\link{data.table}}, \code{\link{as.data.table}}, \code{\link{setDF}}, \code{\link{copy}}, \code{\link{setkey}}, \code{\link{setcolorder}}, \code{\link{setattr}}, \code{\link{setnames}}, \code{\link{set}}, \code{\link{:=}}, \code{\link{setorder}}
30+
\seealso{
31+
\code{\link{data.table}}, \code{\link{as.data.table}}, \code{\link{setDF}}, \code{\link{copy}}, \code{\link{setkey}}, \code{\link{setcolorder}}, \code{\link{setattr}}, \code{\link{setnames}}, \code{\link{set}}, \code{\link{:=}}, \code{\link{setorder}}
2932
}
3033
\examples{
3134
3235
set.seed(45L)
33-
X = data.frame(A=sample(3, 10, TRUE),
34-
B=sample(letters[1:3], 10, TRUE),
35-
C=sample(10), stringsAsFactors=FALSE)
36+
X = data.frame(
37+
A=sample(3, 10, TRUE),
38+
B=sample(letters[1:3], 10, TRUE),
39+
C=sample(10))
3640
3741
# Convert X to data.table by reference and
3842
# get the frequency of each "A,B" combination

0 commit comments

Comments
 (0)