From e9a4a8a8a3af52e16a3829f6f46d8b2c3bef8899 Mon Sep 17 00:00:00 2001 From: jangorecki Date: Sun, 12 May 2019 17:08:16 +0530 Subject: [PATCH 1/5] .Last.updated manual entry --- NEWS.md | 2 +- man/last.updated.Rd | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 man/last.updated.Rd diff --git a/NEWS.md b/NEWS.md index 84370cf098..79f7e8d70b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -71,7 +71,7 @@ setnafill(DT, "locf") ## DT in-place 0.367s ``` -7. New variable `.Last.updated` (similar to R's `.Last.value`) contains the number of rows affected by the most recent `:=` or `set()`, [#1885](https://github.com/Rdatatable/data.table/issues/1885). +7. New variable `.Last.updated` (similar to R's `.Last.value`) contains the number of rows affected by the most recent `:=` or `set()`, [#1885](https://github.com/Rdatatable/data.table/issues/1885). For details see `?.Last.updated`. #### BUG FIXES diff --git a/man/last.updated.Rd b/man/last.updated.Rd new file mode 100644 index 0000000000..d71a4c498e --- /dev/null +++ b/man/last.updated.Rd @@ -0,0 +1,28 @@ +\name{.Last.updated} +\alias{.Last.updated} +\alias{Last.updated} +\title{ Number of rows affected by last update } +\description{ + Returns number of rows affected by last update using \code{:=} operator. +} +\usage{ + .Last.updated +} +\value{ + Integer. +} +\details{ + Be aware that updates on duplicated indices will report actual number of + updates performed, including duplicated ones. See examples. +} +\examples{ +d = data.table(a=1:4, b=2:5) +d[2:3, z:=5L] +.Last.updated + +# updated count takes duplicates into account #2837 +DT = data.table(a = 1L) +DT[c(1L, 1L), a := 2:3] +.Last.updated +} +\keyword{ data } From d21bbafccc38bce5b9b75505d32205bc2cc5ef75 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Sun, 12 May 2019 22:57:46 +0800 Subject: [PATCH 2/5] changed wording re:duplicates --- man/last.updated.Rd | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/man/last.updated.Rd b/man/last.updated.Rd index d71a4c498e..840f9a9a40 100644 --- a/man/last.updated.Rd +++ b/man/last.updated.Rd @@ -12,7 +12,8 @@ Integer. } \details{ - Be aware that updates on duplicated indices will report actual number of + Be aware that in the case of duplicate indices, multiple updates occur (duplicates are overwritten); + \code{.Last.updated} will include \emph{all} of the updates performed, including duplicated ones. See examples. } \examples{ From 6c8fbf538d6b8ae7f8a769aa658d43469f934c49 Mon Sep 17 00:00:00 2001 From: jangorecki Date: Mon, 13 May 2019 09:10:07 +0530 Subject: [PATCH 3/5] update manuals for .Last.updated --- man/assign.Rd | 4 +++- man/last.updated.Rd | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/man/assign.Rd b/man/assign.Rd index 6a8edd2877..9d86b6ee52 100644 --- a/man/assign.Rd +++ b/man/assign.Rd @@ -44,6 +44,8 @@ set(x, i = NULL, j, value) DT[,`:=`(new1 = sum(colB), new2 = sum(colC))] # Functional form } +It is possible to obtain number of rows updated by most recent \code{:=} or \code{set} calls using \code{.Last.updated} variable. For details see \code{\link{.Last.updated}}. + Note that for efficiency no check is performed for duplicate assignments, i.e. if multiple values are passed for assignment to the same index, assignment to this index will occur repeatedly and sequentially; for a given use case, consider whether it makes sense to create your own test for duplicates, e.g. in production code. All of the following result in a friendly error (by design) : @@ -78,7 +80,7 @@ Since \code{[.data.table} incurs overhead to check the existence and type of arg \value{ \code{DT} is modified by reference and returned invisibly. If you require a copy, take a \code{\link{copy}} first (using \code{DT2 = copy(DT)}). } -\seealso{ \code{\link{data.table}}, \code{\link{copy}}, \code{\link{alloc.col}}, \code{\link{truelength}}, \code{\link{set}} +\seealso{ \code{\link{data.table}}, \code{\link{copy}}, \code{\link{alloc.col}}, \code{\link{truelength}}, \code{\link{set}}, \code{\link{.Last.updated}} } \examples{ DT = data.table(a = LETTERS[c(3L,1:3)], b = 4:7) diff --git a/man/last.updated.Rd b/man/last.updated.Rd index 840f9a9a40..5fb9746b38 100644 --- a/man/last.updated.Rd +++ b/man/last.updated.Rd @@ -16,6 +16,9 @@ \code{.Last.updated} will include \emph{all} of the updates performed, including duplicated ones. See examples. } +\seealso{ + \code{\link{:=}} +} \examples{ d = data.table(a=1:4, b=2:5) d[2:3, z:=5L] From c618be6bbae040915206355f2585f751001ef862 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Mon, 13 May 2019 11:51:21 +0800 Subject: [PATCH 4/5] grammar/active voice --- man/assign.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/assign.Rd b/man/assign.Rd index 9d86b6ee52..1b2dd6b9f3 100644 --- a/man/assign.Rd +++ b/man/assign.Rd @@ -44,7 +44,7 @@ set(x, i = NULL, j, value) DT[,`:=`(new1 = sum(colB), new2 = sum(colC))] # Functional form } -It is possible to obtain number of rows updated by most recent \code{:=} or \code{set} calls using \code{.Last.updated} variable. For details see \code{\link{.Last.updated}}. +The \code{\link{.Last.updated}} variable contains the number of rows updated by the most recent \code{:=} or \code{set} calls, which may be useful, for example, in production settings for testing assumptions about the number of rows affected by a statement; see \code{\link{.Last.updated}} for details. Note that for efficiency no check is performed for duplicate assignments, i.e. if multiple values are passed for assignment to the same index, assignment to this index will occur repeatedly and sequentially; for a given use case, consider whether it makes sense to create your own test for duplicates, e.g. in production code. From 0095c36564e50505cf625b08b0b81f7ec3907511 Mon Sep 17 00:00:00 2001 From: Matt Dowle Date: Mon, 13 May 2019 10:19:53 -0700 Subject: [PATCH 5/5] Added set() to description --- man/last.updated.Rd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/man/last.updated.Rd b/man/last.updated.Rd index 5fb9746b38..3b70ba635a 100644 --- a/man/last.updated.Rd +++ b/man/last.updated.Rd @@ -3,7 +3,7 @@ \alias{Last.updated} \title{ Number of rows affected by last update } \description{ - Returns number of rows affected by last update using \code{:=} operator. + Returns number of rows affected by last \code{:=} or \code{set()}. } \usage{ .Last.updated