Added shallow search for data.table in tables()#7580
Added shallow search for data.table in tables()#7580
Conversation
…o feat/adding_list_search_to_tables
|
Hello, I created a new PR in replacement of #7568 Reasons: There was some git issue there and the merge became too complex and I changed the algo because I didnt know previously that rbind or cbind would cost for re-allocation The current PR considers that part and avoids appends Previous PR : creating seperate data.table called info and rbind at the end |
|
In reply to previous comment of @jangorecki An example of when this new feature could be useful? To support lists which occur due to split.data.table or fread like the following The original code supported data.table() top level and this code adds support for list(data.table) if the arg |
|
Example of the original code and the new feature is as follows
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7580 +/- ##
=======================================
Coverage 99.02% 99.03%
=======================================
Files 87 87
Lines 16896 16937 +41
=======================================
+ Hits 16732 16773 +41
Misses 164 164 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
No obvious timing issues in HEAD=feat/adding_list_search_to_tables Generated via commit c65ff92 Download link for the artifact containing the test results: ↓ atime-results.zip
|
…o feat/adding_list_search_to_tables
| #2606 tables() depth=1 finds nested data.tables in lists | ||
| # creating env so that the names are within it | ||
| xenv2 = new.env() | ||
| xenv2$DT = data.table(a = 1L) |
There was a problem hiding this comment.
nit: data.table style is to omit spaces before and after named arguments: data.table(a=1L)
| test(2366.2, tables(env = xenv2, depth = 1L, index = TRUE)$INDICES, list(NULL, NULL, NULL, "b")) | ||
| setkey(xenv2$M$b, a) | ||
| test(2366.3, tables(env = xenv2, depth = 1L, index = TRUE)$KEY, list(NULL, NULL, NULL, "a")) | ||
| test(2366.4, tryCatch(tables(env = xenv2, depth = 2L), error = function(e) e$message), "depth > 1L is not implemented yet") |
There was a problem hiding this comment.
don't use tryCatch like this in our suite; you can use the error= argument.
| test(2366.4, tryCatch(tables(env = xenv2, depth = 2L), error = function(e) e$message), "depth > 1L is not implemented yet") | ||
| rm(xenv2) | ||
|
|
||
| # no data.table test and depth >1 test |
There was a problem hiding this comment.
comment is maybe in the wrong place?
| # creating env so that the names are within it | ||
| xenv2 = new.env() | ||
| xenv2$DT = data.table(a = 1L) | ||
| xenv2$L = list(data.table(a = 1, b = 4:6), data.table(a = 2, b = 7:10)) |
There was a problem hiding this comment.
this test should also include a further-nested table to demonstrate that depth=1L is honored:
xenv2$LL = list(list(data.table(a=1L, b=4:6)))There, we'd need depth=2L to find the data.table, AIUI.
|
|
||
| #2606 tables() depth=1 finds nested data.tables in lists | ||
| # creating env so that the names are within it | ||
| xenv2 = new.env() |
There was a problem hiding this comment.
why xenv2? Where is xenv?
| \item{env}{ An \code{environment}, typically the \code{.GlobalEnv} by default, see Details. } | ||
| \item{silent}{ \code{logical}; should the output be printed? } | ||
| \item{index}{ \code{logical}; if \code{TRUE}, the column \code{INDICES} is added to indicate the indices assorted with each object, see \code{\link{indices}}. } | ||
| \item{depth}{\code{integer}; if \code{1L}, searches for \code{data.table} objects inside top-level lists. If depth = 0L it accepts data.table and Values greater than \code{1L} are not implemented yet.} |
There was a problem hiding this comment.
| \item{depth}{\code{integer}; if \code{1L}, searches for \code{data.table} objects inside top-level lists. If depth = 0L it accepts data.table and Values greater than \code{1L} are not implemented yet.} | |
| \item{depth}{\code{integer}, default \code{0L}. Larger values govern the depth of search in recursive objects like lists or environments. For example, \code{depth=1L} will find all data.tables in the global environment as well as all data.tables in lists (but in lists of lists). NB: \code{depth > 1L} is not yet supported.} |

Closes #2606
added arg
depth = 1Lto tables() one for shallow searchif
depthis 0 then its the data.tableif
depthis 1, we loop through list-like objects using is.list and which are not data.table or data.frameif
depth> 1, we throw erroradded name for the nested list found
parent[[1]]orparent$childpre-allocating info to avoid reallocation cost