Skip to content

Commit

Permalink
Document numbers 3 and 6 for knitr auto-printing
Browse files Browse the repository at this point in the history
  • Loading branch information
aitap committed Oct 9, 2024
1 parent e973bfc commit ffeb415
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion R/print.data.table.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,15 @@ print.data.table = function(x, topn=getOption("datatable.print.topn"),
( length(SYS) >= 3L && is.symbol(thisSYS <- SYS[[length(SYS)-2L]][[1L]]) &&
as.character(thisSYS) == 'source') || # suppress printing from source(echo = TRUE) calls, #2369
( length(SYS) > 3L && is.symbol(thisSYS <- SYS[[length(SYS)-3L]][[1L]]) &&
as.character(thisSYS) %chin% mimicsAutoPrint ) ||
as.character(thisSYS) %chin% mimicsAutoPrint ) || # suppress printing from knitr, #6509
# In previous versions of knitr, call stack when auto-printing looked like:
# knit_print -> knit_print.default -> normal_print -> print -> print.data.table
# and we detected and avoided that by checking fourth last call in the stack.
# As of September 2024, the call stack can also look like:
# knit_print.default -> normal_print -> render -> evalq -> evalq -> print -> print.data.table
# so we have to check the 7th last call in the stack too.
# Ideally, we would like to return invisibly from DT[, foo := bar] and have knitr respect that, but a flag in
# .Primitive("[") sets all values returned from [.data.table to visible, hence the need for printing hacks later.
( length(SYS) > 6L && is.symbol(thisSYS <- SYS[[length(SYS)-6L]][[1L]]) &&
as.character(thisSYS) %chin% mimicsAutoPrint ) ) {
return(invisible(x))
Expand Down

0 comments on commit ffeb415

Please sign in to comment.