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 16897 16938 +41
=======================================
+ Hits 16733 16774 +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 8d0f470 Download link for the artifact containing the test results: ↓ atime-results.zip
|
…o feat/adding_list_search_to_tables
inst/tests/tests.Rraw
Outdated
| #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)
inst/tests/tests.Rraw
Outdated
| 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.
inst/tests/tests.Rraw
Outdated
| 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?
inst/tests/tests.Rraw
Outdated
| # 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.
inst/tests/tests.Rraw
Outdated
|
|
||
| #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?
Co-authored-by: Michael Chirico <chiricom@google.com>
|
Hello @MichaelChirico , I have added the suggested changes. |

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