[R-pkg-devel] Removing import(methods) stops exporting S4 "meta name"

Ivan Krylov |kry|ov @end|ng |rom d|@root@org
Fri Mar 15 13:01:18 CET 2024


On Thu, 14 Mar 2024 16:06:50 -0400
Duncan Murdoch <murdoch.duncan using gmail.com> wrote:

> Error in xj[i] : invalid subscript type 'list'
> Calls: join_inner -> data.frame -> [ -> [.data.table -> [.data.frame
> Execution halted

And here's how it happens:

join_inner calls xi[yi,on=by,nomatch=0] on data.tables xi and yi.

`[.data.table` calls cedta() to determine whether the calling
environment is data.table-aware. If the import of `.__T__[:base` is
removed, cedta() returns FALSE.

`[.data.table` then forwards the call to `[.data.frame`, which cannot
handle data.table-style subsetting.

This is warned about in
<https://cran.r-project.org/package=data.table/vignettes/datatable-importing.html#data-table-in-imports-but-nothing-imported>;
the 'do' package should have set the .datatable.aware = TRUE marker in
its environment. In fact, example(join_inner) doesn't raise an error
with the following changes when running with data.table commit f92aee69
(i.e. pre-#6001):

diff -rU2 do/NAMESPACE do_2.0.0.0.2/NAMESPACE
--- do/NAMESPACE	2021-08-03 12:37:00.000000000 +0300
+++ do_2.0.0.0.2/NAMESPACE	2024-03-15 14:01:10.588561222 +0300
@@ -130,5 +130,4 @@
 export(upper.dir)
 export(write_xlsx)
-importFrom(data.table,`.__T__[:base`)
 importFrom(methods,as)
 importFrom(reshape2,melt)
diff -rU2 do/R/join.R do_2.0.0.0.2/R/join.R
--- do/R/join.R	2020-06-30 06:47:22.000000000 +0300
+++ do_2.0.0.0.2/R/join.R	2024-03-15 13:54:02.289440613 +0300
@@ -1,2 +1,4 @@
+.datatable.aware = TRUE
+
 #' @title Join two dataframes together
 #' @description Join two dataframes by the same id column.

-- 
Best regards,
Ivan



More information about the R-package-devel mailing list