Skip to content

Commit

Permalink
improve copy docs (#4590)
Browse files Browse the repository at this point in the history
  • Loading branch information
jangorecki authored Jun 14, 2021
1 parent 24191e7 commit 2791043
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
5 changes: 4 additions & 1 deletion man/address.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 7 additions & 3 deletions man/copy.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2791043

Please sign in to comment.