Я надеялся расширить печать в файл PDF с использованием grid.table в r - слишком много строк для размещения на одной странице , чтобы добавить заголовок в PDF
title <- "Table 1: Iris Data"
d <- iris[sample(nrow(iris), 187, TRUE),]
d$another <- "More Data"
d$column <- "Even More Will it Be off the Page"
The Provided Answer
library(gridExtra)
library(grid)
d <- iris[sample(nrow(iris), 187, TRUE),]
d$another <- "More Data"
d$column <- "Even More Will it Be off the Page"
tg <- tableGrob(d, rows = seq_len(nrow(d)))
fullheight <- convertHeight(sum(tg$heights), "cm", valueOnly = TRUE)
margin <- unit(0.51,"in")
margin_cm <- convertHeight(margin, "cm", valueOnly = TRUE)
a4height <- 29.7 - margin_cm
nrows <- nrow(tg)
npages <- ceiling(fullheight / a4height)
heights <- convertHeight(tg$heights, "cm", valueOnly = TRUE)
rows <- cut(cumsum(heights), include.lowest = FALSE,
breaks = c(0, cumsum(rep(a4height, npages))))
groups <- split(seq_len(nrows), rows)
gl <- lapply(groups, function(id) tg[id,])
pdf("multipage.pdf", paper = "a4", width = 0, height = 0)
for(page in seq_len(npages)){
grid.newpage()
grid.rect(width=unit(21,"cm") - margin,
height=unit(29.7,"cm")- margin)
grid.draw(gl[[page]])
}
## alternative to explicit loop:
## print(marrangeGrob(grobs=gl, ncol=1, nrow=1, top=NULL))
dev.off()
Как я могу изменить этот код, чтобы я мог добавить title
на первую страницу PDF?