Skip to content

Commit a68392f

Browse files
add header to match keystyle
1 parent 79f5923 commit a68392f

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed

R/print.data.table.R

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,23 @@ print.data.table = function(x, topn=getOption("datatable.print.topn"),
6363
return(invisible(x))
6464
}
6565
if (show.indices) {
66-
if (is.null(indices(x))) {
67-
show.indices = FALSE
68-
} else {
69-
index_dt <- as.data.table(attributes(attr(x, 'index')))
70-
print_names <- paste0("index", if (ncol(index_dt) > 1L) seq_len(ncol(index_dt)) else "", ":", sub("^__", "", names(index_dt)))
71-
setnames(index_dt, print_names)
66+
indices <- names(attr(x, "index", exact = TRUE)) # Get actual index names
67+
if (length(indices)) {
68+
# Clean index formatting
69+
cleaned_indices <- gsub("^__|_", ", ", indices)
70+
cleaned_indices <- sub(", $", "", cleaned_indices)
71+
# Create header string (matches key display style)
72+
header <- paste0("Indices: ", paste(cleaned_indices, collapse = ", "))
73+
74+
# Add to existing header metadata instead of toprint
75+
if (exists("header", envir = parent.frame(), inherits = FALSE)) {
76+
assign("header", c(get("header", envir = parent.frame()), header),
77+
envir = parent.frame())
7278
}
7379
}
80+
else {
81+
show.indices <- FALSE
82+
}
7483
n_x = nrow(x)
7584
if ((topn*2L+1L)<n_x && (n_x>nrows || !topnmiss)) {
7685
toprint = rbindlist(list(head(x, topn), tail(x, topn)), use.names=FALSE) # no need to match names because head and tail of same x, and #3306

0 commit comments

Comments
 (0)