您可以将对象的打印操作为常规字符向量.
library(data.table) options(datatable.print.nrows = Inf) dt = data.table(sample.int(2e3, 1e4, T)) myprint = function(x){ prnt = capture.output(print(x)) cat(prnt[-length(prnt)], sep="\n") } myprint(dt[ , .(.N), V1])