I pretty much copied word-for-word the example from this site on how to create multiple PDFs in knitr from one for-loop: http://www.reed.edu/data-at-reed/software/R/markdown_multiple_reports.html
When I try calling knitr::kable(cars)
or kable(cars)
the output of each PDF appears as one long column instead of an actual table, as shown in the photo.
Any idea what causes this? Here's the .R and the .Rmd code called in each iteration of the loop:
.R
library(knitr)
library(markdown)
library(rmarkdown)
mt <- mtcars[1:5,]
for (car in unique(rownames(mt))){
rmarkdown::render('test.Rmd',
output_format = "pdf_document",
output_file = paste(car, ' report.pdf', sep=''),
output_dir = '~/')
test.Rmd
library(knitr)
library(markdown)
library(rmarkdown)
cars <- mtcars[rownames(mtcars)==car,]
# create example data
x <- sample(1:10, 1)
cars <- do.call("rbind", replicate(x, cars, simplify = FALSE))
# create hypothetical lat and lon data
cars$lat <- sapply(rownames(cars), function(x) round(runif(1, 30, 46), 3))
cars$lon <- sapply(rownames(cars), function(x) round(runif(1, -115, -80),3))
knitr::kable(cars)
kable(cars)
I was able to get are relatively normal looking table by using kable(cars, format = "latex")
I was hoping to get some quick and decent html tables, and now when I try to format in LaTeX with something like kable(cars, format = "latex", booktabs = T)
, I get this error:
pandoc: Error producing PDF
Error: pandoc document conversion failed with error 43