Wonderful R package! I want to render multiple tables in the same document using a for loop. I noticed that the table doesn't render inside a for loop (see below). It renders if you enclose the table call in a print statement.
---
title: Gapminder data (test table1)
output:
html_document
---
\```{r echo=F}
suppressPackageStartupMessages({
library(table1)
library(gapminder)
})
label(gapminder$continent) <- "Continent"
label(gapminder$lifeExp) <- "Life expectency at birth (years)"
label(gapminder$gdpPercap) <- "GDP per capita (US$, inflation-adjusted)"
\```
Table 1:
\```{r echo=F, results='asis'}
for (i in c(1)){
table1(~ continent + lifeExp + gdpPercap, data=gapminder)
}
\```
Table 2:
\```{r echo=F, results='asis'}
for (i in c(1)){
print(table1(~ continent + lifeExp + gdpPercap, data=gapminder))
}
\```
Table3:
\```{r echo=F, results='asis'}
table1(~ continent + lifeExp + gdpPercap, data=gapminder)
\```
Yes, this is expected behavior. A lot of R packages work like that, i.e., the object won't be displayed until it is printed, which happens automatically at the top level, but must be done explicitly inside loops.
Hi,
Wonderful R package! I want to render multiple tables in the same document using a for loop. I noticed that the table doesn't render inside a for loop (see below). It renders if you enclose the table call in a print statement.