-
Notifications
You must be signed in to change notification settings - Fork 1k
Added shallow search for data.table in tables() #7580
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
803f763
b9fdca8
107a65b
ca8701e
174b0ea
03e58c9
3ba7c1b
1e1fd11
1952290
40a188d
0f70dc9
2f19256
afd197a
b591887
866820a
2880f1e
c65ff92
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21515,3 +21515,29 @@ test(2365.1, melt(df_melt, id.vars=1:2), melt(dt_melt, id.vars=1:2)) | |
| df_dcast = data.frame(a = c("x", "y"), b = 1:2, v = 3:4) | ||
| dt_dcast = data.table(a = c("x", "y"), b = 1:2, v = 3:4) | ||
| test(2365.2, dcast(df_dcast, a ~ b, value.var = "v"), dcast(dt_dcast, a ~ b, value.var = "v")) | ||
|
|
||
| #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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: data.table style is to omit spaces before and after named arguments: |
||
| xenv2$L = list(data.table(a = 1, b = 4:6), data.table(a = 2, b = 7:10)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this test should also include a further-nested table to demonstrate that xenv2$LL = list(list(data.table(a=1L, b=4:6)))There, we'd need |
||
| xenv2$M = list(b = data.table(a = 1, b = 4:6), a = 1:5) | ||
| xenv2$N = list(a = 1:5) | ||
| test(2366.1, tables(env = xenv2, depth = 1L)[, .(NAME, NROW, NCOL)], | ||
| data.table( | ||
| NAME = c("DT", "L[[1]]", "L[[2]]", "M$b"), | ||
| NROW = c(1L, 3L, 4L, 3L), | ||
| NCOL = c(1L, 2L, 2L, 2L) | ||
| )) | ||
| setindex(xenv2$M$b, b) | ||
| 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") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't use tryCatch like this in our suite; you can use the |
||
| rm(xenv2) | ||
|
|
||
| # no data.table test and depth >1 test | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment is maybe in the wrong place? |
||
| xenv_empty = new.env() | ||
| test(2366.5, tables(env = xenv_empty, depth = 1L), invisible(data.table(NULL))) | ||
| test(2366.6, tables(env = xenv_empty), invisible(data.table(NULL))) | ||
| rm(xenv_empty) | ||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |||||
| } | ||||||
| \usage{ | ||||||
| tables(mb=type_size, order.col="NAME", width=80, | ||||||
| env=parent.frame(), silent=FALSE, index=FALSE) | ||||||
| env=parent.frame(), silent=FALSE, index=FALSE, depth=0L) | ||||||
| } | ||||||
| \arguments{ | ||||||
| \item{mb}{ a function which accepts a \code{data.table} and returns its size in bytes. By default, \code{type_size} (same as \code{TRUE}) provides a fast lower bound by excluding the size of character strings in R's global cache (which may be shared) and excluding the size of list column items (which also may be shared). A column \code{"MB"} is included in the output unless \code{FALSE} or \code{NULL}. } | ||||||
|
|
@@ -15,6 +15,7 @@ tables(mb=type_size, order.col="NAME", width=80, | |||||
| \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.} | ||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| } | ||||||
| \details{ | ||||||
| Usually \code{tables()} is executed at the prompt, where \code{parent.frame()} returns \code{.GlobalEnv}. \code{tables()} may also be useful inside functions where \code{parent.frame()} is the local scope of the function; in such a scenario, simply set it to \code{.GlobalEnv} to get the same behaviour as at prompt. | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why
xenv2? Where isxenv?