Closed stephenkirk closed 6 years ago
hux(as_hux(...)) is redundant, just call as_hux.
Yes, it's an autoprinting issue. Cf. ggplot. I'm not sure why print() doesn't work though. Try doing print_latex in your for loop. Does that work?
You will probably also need to set "results = 'asis'" in the knitr header
David
On 19 October 2017 at 12:28, David Hugh-Jones davidhughjones@gmail.com wrote:
hux(as_hux(...)) is redundant, just call as_hux.
Yes, it's an autoprinting issue. Cf. ggplot. I'm not sure why print() doesn't work though. Try doing print_latex in your for loop. Does that work?
I'm having a similar problem with a for
loop. I've tried the print_latex()
and the making the rmarkdown section results='asis'
however it does create strange behaviours.
huxtable
kitting the document throws latex errors for tabularxThe following is some reprex rmarkdown content to trial.
---
title: "Test"
output:
pdf_document:
keep_tex: yes
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(magrittr)
library(dplyr)
library(huxtable)
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
ht <- hux(
Employee = c('John Smith', 'David Hugh-Jones'),
Salary = c(50000, 50000),
add_colnames = TRUE
)
ht %>%
set_bold(1, everywhere, TRUE) %>%
set_bottom_border(1, everywhere, 1)
df1 <- data.frame("Col1" = c("A","A","B","B","C"),
"Description" = c("Lorem ipsum dolor sit", "blah", "more blah", "Ut enim ad minim", NA),
Some_Numbers = c(10, 1000, 1000000, 25000, 99999999),
more_numbers = c(4235, 345.345, 03575.34, 97534987534890, 78350))
for (i in LETTERS[1:3]) {
tbl1 <- df1 %>% filter(Col1 == i)
tbl2 <- tbl1 %>% summarise(Col1 = "Total",
Some_Numbers = sum(Some_Numbers),
more_numbers = sum(more_numbers))
tbl3 <- bind_rows(tbl1, tbl2) %>%
select(Col1, Description, "Some Numbers" = Some_Numbers, more_numbers)
cat("\n## Year", i, "\n Data for filtered records: ", i, "\n")
print_latex(as_hux(tbl3))
cat("\n")
}
ah, yes. The automatic setting of headers only occurs when the huxtable is directly outputted via its print method. You might try just calling print on it within the loop.
David
On 5 December 2017 at 02:08, Dan notifications@github.com wrote:
I'm having a similar problem with a for loop. I've tried the print_latex() and the making the rmarkdown section results='asis' however it does create strange behaviours.
- It creates a sizeable indentation from the left
- No headers are included in the output.
- without a preliminary huxtable kitting the document throws latex errors for tabularx
The following is some reprex rmarkdown content to trial.
---title: "Test"output: pdf_document: keep_tex: yes---
library(magrittr) library(dplyr) library(huxtable)
R Markdown
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
first huxtable
ht <- hux( Employee = c('John Smith', 'David Hugh-Jones'), Salary = c(50000, 50000), add_colnames = TRUE ) ht %>% set_bold(1, everywhere, TRUE) %>% set_bottom_border(1, everywhere, 1)
looping huxtable test
df1 <- data.frame("Col1" = c("A","A","B","B","C"), "Description" = c("Lorem ipsum dolor sit", "blah", "more blah", "Ut enim ad minim", NA), Some_Numbers = c(10, 1000, 1000000, 25000, 99999999), more_numbers = c(4235, 345.345, 03575.34, 97534987534890, 78350)) for (i in LETTERS[1:3]) { tbl1 <- df1 %>% filter(Col1 == i) tbl2 <- tbl1 %>% summarise(Col1 = "Total", Some_Numbers = sum(Some_Numbers), more_numbers = sum(more_numbers)) tbl3 <- bind_rows(tbl1, tbl2) %>% select(Col1, Description, "Some Numbers" = Some_Numbers, more_numbers) cat("\n## Year", i, "\n Data for filtered records: ", i, "\n") print_latex(as_hux(tbl3)) cat("\n") }
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/hughjonesd/huxtable/issues/31#issuecomment-349171943, or mute the thread https://github.com/notifications/unsubscribe-auth/AFjJ98eqE05AGWxvzxdKQQLcwh6oSvHdks5s9KW4gaJpZM4P_EpF .
Setting: I want to output a latex PDF document. Sometimes, I need to create an arbitrary number of tables – for example, to automatically split tables that become too long to fit on a page.
First things first:
Works as expected - the table appears. However, as soon as the
hux()
call is enclosed in some way, problems appear:Doesn't work - none of the tables appear.
This seems similar to an issue that kable had (https://github.com/yihui/knitr/issues/886), but where the workaround was either an explicit print() or making sure that 'asis' is set.
Experimenting a bit, neither of the following work either:
But interestingly enough, this works:
I've also experimented with calling with
map()
in thepurrr
package without any success.Problem occured both with the 0.3.1 version of
huxtable
, as well as 1.0.0.9. Attached is my sessioninfo:I've tried to track this issue down a bit, but I'm not fully comfortable with the internals of
huxtable
and it'd take me a good while to figure it out. However, I figure that I should report it in case this is a known problem with a simple answer.Beyond this, I'd like to thank you for building such a complete lifesaver of a package.