Skip to content

Commit f1cc4c8

Browse files
committed
updates tests and comments
1 parent a04d3ed commit f1cc4c8

File tree

2 files changed

+23
-26
lines changed

2 files changed

+23
-26
lines changed

R/tables.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ tables = function(mb=type_size, order.col="NAME", width=80L,
6565
found_items = lapply(w, function(i) list(name=names[i], obj=obj[[i]]))
6666
}
6767
}
68-
if (!length(found_items)) { # MODIFIED: Check `found_items` instead of `w`
68+
if (!length(found_items)) {
6969
if (!silent) catf("No objects of class data.table exist in %s%s\n",
7070
if (identical(env, .GlobalEnv)) ".GlobalEnv" else format(env),
71-
if (recursive) " (recursively)" else "") # NEW: More informative message
71+
if (recursive) " (recursively)" else "")
7272
return(invisible(data.table(NULL)))
7373
}
7474
info = data.table(NAME=vapply(found_items, `[[`, "name", FUN.VALUE=character(1L)),

inst/tests/tests.Rraw

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21427,27 +21427,24 @@ test(2330.7, as.data.table(list(z), keep.rownames=TRUE), data.table(rn=rep("", 3
2142721427
M <- matrix(1:6, nrow=3, dimnames=list(rep("", 3), c("V1", "V2"))) # test of list(M) for empty-rowname'd matrix input
2142821428
test(2330.8, as.data.table(list(M), keep.rownames=TRUE), data.table(rn=rep("", 3), V1=1:3, V2=4:6))
2142921429

21430-
#2606
21431-
test(2331.1, {
21432-
dt1 = data.table(a = 1)
21433-
lst = list(inner = dt1)
21434-
res = tables(recursive=TRUE)
21435-
any(res$NAME == "lst$inner")
21436-
}, TRUE)
21437-
test(2331.2, {
21438-
lst = list(data.table(b = 2))
21439-
res = tables(recursive=TRUE)
21440-
any(grepl("^lst\\[\\[1\\]\\]$", res$NAME))
21441-
}, TRUE)
21442-
test(2331.3, {
21443-
nested = list(l1 = list(l2 = data.table(c = 3)))
21444-
res = tables(recursive=TRUE)
21445-
any(res$NAME == "nested$l1$l2")
21446-
}, TRUE)
21447-
test(2331.4, {
21448-
cycle = list()
21449-
cycle[[1]] = cycle
21450-
cycle[[2]] = data.table(x = 1)
21451-
res = tables(recursive=TRUE)
21452-
any(res$NAME == "cycle[[2]]") && !"cycle[[1]]" %in% res$NAME
21453-
}, TRUE)
21430+
#2606 Recursive tables() naming convention
21431+
test(2331.1, local({
21432+
dt1 <- data.table(a = 1)
21433+
lst <- list(inner = dt1)
21434+
"lst$inner" %in% tables(recursive = TRUE)$NAME
21435+
}))
21436+
test(2331.2, local({
21437+
lst <- list(data.table(b = 2))
21438+
"lst[[1]]" %in% tables(recursive = TRUE)$NAME
21439+
}))
21440+
test(2331.3, local({
21441+
nested <- list(l1 = list(l2 = data.table(c = 3)))
21442+
"nested$l1$l2" %in% tables(recursive = TRUE)$NAME
21443+
}))
21444+
test(2331.4, local({
21445+
cycle <- list()
21446+
cycle[[1]] <- cycle
21447+
cycle[[2]] <- data.table(x = 1)
21448+
res <- tables(recursive = TRUE)$NAME
21449+
"cycle[[2]]" %in% res && !"cycle[[1]]" %in% res
21450+
}))

0 commit comments

Comments
 (0)