From 2791043ff29efcfe776896006d0b2dbf013bd7e5 Mon Sep 17 00:00:00 2001 From: Jan Gorecki Date: Mon, 14 Jun 2021 23:41:59 +0200 Subject: [PATCH] improve copy docs (#4590) --- man/address.Rd | 5 ++++- man/copy.Rd | 10 +++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/man/address.Rd b/man/address.Rd index 2c390a3a6..8363d3c7b 100644 --- a/man/address.Rd +++ b/man/address.Rd @@ -16,8 +16,11 @@ Sometimes useful in determining whether a value has been copied or not, programm \value{ A character vector length 1. } +\seealso{ + \code{\link{copy}} +} \references{ -\url{https://stackoverflow.com/a/10913296/403310} (but implemented in C without using \code{.Internal(inspect())}) + \url{https://stackoverflow.com/a/10913296/403310} (but implemented in C without using \code{.Internal(inspect())}) } \examples{ x=1 diff --git a/man/copy.Rd b/man/copy.Rd index 819fa2a50..587f21680 100644 --- a/man/copy.Rd +++ b/man/copy.Rd @@ -16,11 +16,15 @@ copy(x) \code{data.table} provides functions that operate on objects \emph{by reference} and minimise full object copies as much as possible. Still, it might be necessary in some situations to work on an object's copy which can be done using \code{DT.copy <- copy(DT)}. It may also be sometimes useful before \code{:=} (or \code{set}) is used to subassign to a column by reference. A \code{copy()} may be required when doing \code{dt_names = names(DT)}. Due to R's \emph{copy-on-modify}, \code{dt_names} still points to the same location in memory as \code{names(DT)}. Therefore modifying \code{DT} \emph{by reference} now, say by adding a new column, \code{dt_names} will also get updated. To avoid this, one has to \emph{explicitly} copy: \code{dt_names <- copy(names(DT))}. - } +} +\note{ + To confirm precisely whether an object is a copy of another, compare their exact memory address with \code{\link{address}}. +} \value{ - Returns a copy of the object. + Returns a copy of the object. } -\seealso{ \code{\link{data.table}}, \code{\link{setkey}}, \code{\link{setDT}}, \code{\link{setDF}}, \code{\link{set}} \code{\link{:=}}, \code{\link{setorder}}, \code{\link{setattr}}, \code{\link{setnames}} +\seealso{ + \code{\link{data.table}}, \code{\link{address}}, \code{\link{setkey}}, \code{\link{setDT}}, \code{\link{setDF}}, \code{\link{set}} \code{\link{:=}}, \code{\link{setorder}}, \code{\link{setattr}}, \code{\link{setnames}} } \examples{ # Type 'example(copy)' to run these at prompt and browse output