Skip to content

Commit e46debe

Browse files
Remove user-facing references to .internal.selfref (#6698)
* Remove user-facing references to .internal.selfref * Improve test relying on obscure test for duplicate verbose message * Just say "invalid" instead of "missing" * More precise wording about add/remove
1 parent b186024 commit e46debe

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

R/data.table.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ replace_dot_alias = function(e) {
11881188
# ok=-1 which will trigger setalloccol with verbose in the next
11891189
# branch, which again calls _selfrefok and returns the message then
11901190
if ((ok<-selfrefok(x, verbose=FALSE))==0L) # ok==0 so no warning when loaded from disk (-1) [-1 considered TRUE by R]
1191-
if (is.data.table(x)) warningf("Invalid .internal.selfref detected and fixed by taking a (shallow) copy of the data.table so that := can add this new column by reference. At an earlier point, this data.table has been copied by R (or was created manually using structure() or similar). Avoid names<- and attr<- which in R currently (and oddly) may copy the whole data.table. Use set* syntax instead to avoid copying: ?set, ?setnames and ?setattr. If this message doesn't help, please report your use case to the data.table issue tracker so the root cause can be fixed or this message improved.")
1191+
if (is.data.table(x)) warningf("A shallow copy of this data.table was taken so that := can add or remove %d columns by reference. At an earlier point, this data.table was copied by R (or was created manually using structure() or similar). Avoid names<- and attr<- which in R currently (and oddly) may copy the whole data.table. Use set* syntax instead to avoid copying: ?set, ?setnames and ?setattr. It's also not unusual for data.table-agnostic packages to produce tables affected by this issue. If this message doesn't help, please report your use case to the data.table issue tracker so the root cause can be fixed or this message improved.", length(newnames))
11921192
# !is.data.table for DF |> DT(,:=) tests 2212.16-19 (#5113) where a shallow copy is routine for data.frame
11931193
if ((ok<1L) || (truelength(x) < ncol(x)+length(newnames))) {
11941194
DT = x # in case getOption contains "ncol(DT)" as it used to. TODO: warn and then remove

inst/tests/tests.Rraw

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7066,7 +7066,7 @@ ee = new.env()
70667066
ee$DT = data.frame(x=1L, y=1:3)
70677067
setattr(ee$DT, 'class', c("data.table", "data.frame"))
70687068
test(1482.1, truelength(ee$DT), 0L) # make sure that the simulated environment is right.
7069-
test(1482.2, ee$DT[, z := 3:1], data.table(x=1L, y=1:3, z=3:1), warning="Invalid .internal.selfref detected and")
7069+
test(1482.2, ee$DT[, z := 3:1], data.table(x=1L, y=1:3, z=3:1), warning="A shallow copy of this data.table was taken")
70707070
test(1482.3, truelength(ee$DT), 1027L)
70717071
test(1482.4, ee$DT[, za := 4:6], data.table(x=1L, y=1:3, z=3:1, za=4:6))
70727072
test(1482.5, truelength(ee$DT), 1027L) # should have used spare slot i.e. no increase in tl
@@ -14942,7 +14942,7 @@ test(2037.1, foo(DT), output='Please remember to always setDT()')
1494214942
# no assignment was made to DT
1494314943
test(2037.2, names(DT), 'a')
1494414944
# _selrefok() verbose message was duplicated
14945-
test(2037.3, unname(table(unlist(strsplit(capture.output(foo(DT)), '\n|\\s+')))['ptr']), 1L)
14945+
test(2037.3, foo(DT), output="data.table internal attributes", notOutput="data.table internal attributes.*data.table internal attributes")
1494614946

1494714947
# `between` invalid args, and verbose #3516
1494814948
test(2038.01, between(1:5, 2, 4, incbounds=423), error="incbounds must be TRUE or FALSE")

man/all.equal.data.table.Rd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
}
2525

2626
\item{check.attributes}{
27-
A logical indicating whether or not to check attributes, will apply not only to data.table but also attributes of the columns. It will skip \code{c("row.names",".internal.selfref")} data.table attributes.
27+
A logical indicating whether or not to check attributes. Note that this will apply not only to the data.tables, but also to attributes of the columns. \code{"row.names"} and any internal data.table attributes are always skipped.
2828
}
2929

3030
\item{ignore.col.order}{

src/assign.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ static int _selfrefok(SEXP x, Rboolean checkNames, Rboolean verbose) {
119119
}
120120
p = R_ExternalPtrAddr(v);
121121
if (p==NULL) {
122-
if (verbose) Rprintf(_(".internal.selfref ptr is NULL. This is expected and normal for a data.table loaded from disk. Please remember to always setDT() immediately after loading to prevent unexpected behavior. If this table was not loaded from disk or you've already run setDT(), please report to data.table issue tracker.\n"));
122+
if (verbose) Rprintf(_("The data.table internal attributes of this table are invalid. This is expected and normal for a data.table loaded from disk. Please remember to always setDT() immediately after loading to prevent unexpected behavior. If this table was not loaded from disk or you've already run setDT(), please report to the data.table issue tracker.\n"));
123123
return -1;
124124
}
125125
if (!isNull(p)) internal_error(__func__, ".internal.selfref ptr is neither NULL nor R_NilValue"); // # nocov

0 commit comments

Comments
 (0)