Skip to content

Commit b5cee16

Browse files
add changes
1 parent cca0282 commit b5cee16

File tree

3 files changed

+25
-13
lines changed

3 files changed

+25
-13
lines changed

R/data.table.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,7 +1183,7 @@ replace_dot_alias = function(e) {
11831183
} else {
11841184
# Adding new column(s). TO DO: move after the first eval in case the jsub has an error.
11851185
newnames=setdiff(lhs, names_x)
1186-
m[is.na(m)] = ncol(x)+seq_len(length(newnames))
1186+
m[is.na(m)] = ncol(x)+seq_along(newnames)
11871187
cols = as.integer(m)
11881188
# don't pass verbose to selfrefok here -- only activated when
11891189
# ok=-1 which will trigger setalloccol with verbose in the next
@@ -2380,7 +2380,7 @@ subset.data.table = function(x, subset, select, ...)
23802380
## Set the key on the returned data.table as long as the key
23812381
## columns that "remain" are the same as the original, or a
23822382
## prefix of it.
2383-
is.prefix = all(key(x)[seq_len(length(key.cols))] == key.cols)
2383+
is.prefix = all(key(x)[seq_along(key.cols)] == key.cols)
23842384
if (is.prefix) {
23852385
setattr(ans, "sorted", key.cols)
23862386
}
@@ -2867,7 +2867,7 @@ setDF = function(x, rownames=NULL) {
28672867
stopf("All elements in argument 'x' to 'setDF' must be of same length")
28682868
xn = names(x)
28692869
if (is.null(xn)) {
2870-
setattr(x, "names", paste0("V",seq_len(length(x))))
2870+
setattr(x, "names", paste0("V",seq_along(x)))
28712871
} else {
28722872
idx = !nzchar(xn) # NB: keepNA=FALSE intentional
28732873
if (any(idx)) {

R/print.data.table.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ print.data.table = function(x, topn=getOption("datatable.print.topn"),
3232
SYS = sys.calls()
3333
if (identical(SYS[[1L]][[1L]], print) ||
3434
( length(SYS) >= 3L && is.symbol(thisSYS <- SYS[[length(SYS)-2L]][[1L]]) &&
35-
as.character(thisSYS) == 'source') ) {
35+
as.character(thisSYS) == 'source')) {
3636
return(invisible(x))
3737
}
3838
}
@@ -102,15 +102,15 @@ print.data.table = function(x, topn=getOption("datatable.print.topn"),
102102
expression = "<expr>", ordered = "<ord>")
103103
classes = classes1(x)
104104
col_names <- colnames(toprint)
105-
index_cols <- paste0("index:", indices(x))
105+
index_cols <- paste0("index:", indices(x))
106106
for (col_name in col_names) {
107107
if (col_name %in% index_cols) {
108108
classes[col_name] <- "index"
109109
} else if (col_name %in% names(x)) {
110110
cls <- class(x[[col_name]])
111-
if (is.list(cls)) cls <- unlist(cls)
112-
if (length(cls) == 0) cls <- "unknown"
113-
classes[col_name] <- cls[1]
111+
if (is.list(cls)) cls <- unlist(cls)
112+
if (length(cls) == 0) cls <- "unknown"
113+
classes[col_name] <- cls[1]
114114
} else {
115115
classes[col_name] <- "unknown"
116116
}

inst/tests/tests.Rraw

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18784,11 +18784,6 @@ ans = c(
1878418784
"10: 83 64 41 9 9")
1878518785
# test where topn isn't necessary
1878618786
test(2264.8, print(DT, show.indices=TRUE), output=ans)
18787-
# printing does not fail when indices are present
18788-
test(2264.9, {
18789-
suppressWarnings( print(DT, show.indices=TRUE) )
18790-
TRUE
18791-
})
1879218787

1879318788
# integer64 columns print even when bit64 isn't loaded
1879418789
if (test_bit64) local({
@@ -21046,3 +21041,20 @@ test(2304.100, set(copy(DT), i=2L, j=c("L1", "L2"), value=list(list(NULL), list(
2104621041

2104721042
# the integer overflow in #6729 is only noticeable with UBSan
2104821043
test(2305, { fread(testDir("issue_6729.txt.bz2")); TRUE })
21044+
21045+
# Tests for print.data.table handling index columns, list classes, and unknown classes in #6806
21046+
21047+
# Test for covering classes[col_name] <- "index"
21048+
DT = data.table(A = 1:3, B = 4:6)
21049+
setindex(DT, A)
21050+
test(108, DT, data.table(t(t(DT)), key = "A"))
21051+
# Test for covering if (is.list(cls)) cls <- unlist(cls)
21052+
DT = data.table(A = 1:3, B = list(NULL, NULL, NULL))
21053+
test(109, DT, data.table(t(t(DT))))
21054+
# Test for covering if (length(cls) == 0) cls <- "unknown"
21055+
DT = data.table(A = 1:3, B = I(list()))
21056+
test(110, DT, data.table(t(t(DT))))
21057+
# Test for covering classes[col_name] <- "unknown"
21058+
DT = data.table(A = 1:3, B = 4:6, C = 7:9)
21059+
DT[, D := NULL]
21060+
test(111, DT, data.table(t(t(DT))))

0 commit comments

Comments
 (0)