I have a markdown file template.Rmd
that processes some data and displays some charts. All works fine when I run the file from within Rstudio with the file open and selecting knit > knit to html
.
But when I try to render via a script, the output is generated and saved to a directory, but when I open it only text is shown, no charts.
My template.Rmd file. I use backslashes \
to try to get around using 3 backticks for markdown in my doc Vs. on this posts page so the post renders more readable code blocks. (but those backslashes don't exist on my actual file):
---
title: "ModelMultipliers"
output: html_document
---
\```{r setup, include=FALSE}
knitr::opts_chunk$set(
echo = FALSE,
message = FALSE,
warning = FALSE
)
pacman::p_load(tidyverse, lubridate, Metrics, foreach, ggpubr, DT)
code here
\```
\```{r preprocessing, include=FALSE}
code here
\```
# Blah
Some blocks of text here
\```{r explore, echo=FALSE, message=FALSE, warning=FALSE, paged.print=FALSE}
# some code that generates some ggplots which are meant to be visible
\```
\```{r modeling, echo=FALSE, message=FALSE, warning=FALSE, paged.print=FALSE}
# some more code that generates some ggplots which are meant to be visible
\```
\```{r plots, echo=FALSE, message=FALSE, warning=FALSE, paged.print=FALSE}
# some code that generates some ggplots which are meant to be visible```
\```
If I run this within Rstudio UI, all is well, the desired html output is rendered and pops up after rendering. I see lots of charts.
But when I try to run via a script with the block below, only the text is shown, no charts:
library(tidyverse)
GAME <- Sys.getenv('GAME')
CURRDATE <- Sys.Date() %>% as.character()
rmarkdown::render("template.Rmd",
output_format = "html_document",
output_file = paste0('_', CURRDATE, '_', GAME, '.html'),
output_dir = paste0('runs/', GAME)
)
The file is generated and shows in the right directory, just no visuals.
Why does rendering this way as opposed to the UI drop the visuals? Is that expected? How can I get around this so as when I call rmarkdown::render()
the file is generated including the charts?