[Rd] head.matrix can return 1000s of columns -- limit to n or add new argument?

Michael Chirico m|ch@e|ch|r|co4 @end|ng |rom gm@||@com
Mon Jul 8 11:40:53 CEST 2019


I think of head() as a standard helper for "glancing" at objects, so I'm
sometimes surprised that head() produces massive output:

M = matrix(nrow = 10L, ncol = 100000L)
print(head(M)) # <- beware, could be a huge print

I assume there are lots of backwards-compatibility issues as well as valid
use cases for this behavior, so I guess defaulting to M[1:6, 1:6] is out of
the question.

Is there any scope for adding a new argument to head.matrix that would
allow this flexibility? IINM it should essentially be as simple to do
head.array as:

do.call(`[`, c(list(x, drop = FALSE), lapply(pmin(dim(x), n), seq_len)))

(with extra decoration to handle -n, etc)

	[[alternative HTML version deleted]]



More information about the R-devel mailing list