Skip to content

Commit 07d45c6

Browse files
committed
faq updated
1 parent 6f49bf1 commit 07d45c6

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

man/setDT.Rd

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ setDT(x, keep.rownames=FALSE, key=NULL, check.names=FALSE)
2828
}
2929
3030
\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}}
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}},
32+
See the FAQ vignette: \code{vignette("datatable-faq", package = "data.table")}.
3233
}
3334
\examples{
3435
@@ -58,6 +59,14 @@ setDT(X, key="a")[]
5859
X = list(a=1:5, a=6:10)
5960
setDT(X, check.names=TRUE)[]
6061

62+
# FAQ: Dealing with data.table loaded from RDS or RData files
63+
# Example to demonstrate the usage of setDT after loading from RDS
64+
if (file.exists("my_data.rds")) {
65+
X = readRDS("my_data.rds") # Load data.table from RDS if file exists
66+
setDT(X) # Make sure to use setDT() after loading
67+
} else {
68+
message("my_data.rds file does not exist. Skipping RDS loading example.")
69+
}
6170
}
6271
\keyword{ data }
6372

man/truelength.Rd

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ alloc.col(DT,
4444
\code{setalloccol} \emph{reallocates} \code{DT} by reference. This may be useful for efficiency if you know you are about to going to add a lot of columns in a loop.
4545
It also returns the new \code{DT}, for convenience in compound queries.
4646
}
47-
\seealso{ \code{\link{copy}} }
47+
\seealso{ \code{\link{copy}}, See the FAQ vignette: \code{vignette("datatable-faq", package = "data.table")}.}
4848
\examples{
4949
DT = data.table(a=1:3,b=4:6)
5050
length(DT) # 2 column pointer slots used
@@ -54,5 +54,14 @@ length(DT) # 2 used
5454
truelength(DT) # 2050 allocated, 2048 free
5555
DT[,c:=7L] # add new column by assigning to spare slot
5656
truelength(DT)-length(DT) # 2047 slots spare
57+
58+
# FAQ: Dealing with data.table loaded from RDS or RData files
59+
# Example to demonstrate the usage of setDT after loading from RDS
60+
if (file.exists("my_data.rds")) {
61+
X = readRDS("my_data.rds") # Load data.table from RDS if file exists
62+
setDT(X) # Make sure to use setDT() after loading
63+
} else {
64+
message("my_data.rds file does not exist. Skipping RDS loading example.")
65+
}
5766
}
5867
\keyword{ data }

vignettes/datatable-faq.Rmd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,10 @@ DT[ , b := rnorm(5)] # 'replace' integer column with a numeric column
620620

621621
## Reading data.table from RDS or RData file
622622

623-
`*.RDS` and `*.RData` are file types which can store in-memory R objects on disk efficiently. However, storing data.table into the binary file loses its column over-allocation. This isn't a big deal -- your data.table will be copied in memory on the next _by reference_ operation and throw a warning. Therefore it is recommended to call `setalloccol()` on each data.table loaded with `readRDS()` or `load()` calls.
623+
`*.RDS` and `*.RData` are file types which can store in-memory R objects on disk efficiently. However, storing `data.table` into a binary file loses its column over-allocation and `truelength()`. This isn't a big deal -- your `data.table` will be copied in memory on the next _by reference_ operation and throw a warning.
624+
Therefore, it is recommended to call `setDT()` on each `data.table` loaded with `readRDS()` or `load()` calls to restore its internal attributes. If you only need to pre-allocate space for new columns, `setalloccol()` can also be used.
625+
626+
For more details, see `?setDT` and `?truelength`.
624627

625628
# General questions about the package
626629

0 commit comments

Comments
 (0)