Hi All.
I'm new to R and just dipping my toes into programming in general, so please excuse any potentially huge gaps in knowledge/stupidity.
I've created a large 33mb Rmarkdown report which generates a number of graphs relating to organisational performance metrics at departmental-level. My current process has been to knit this file every morning, and then manually save the .html output in a network folder so it can be accessed by various interested users scattered across the company.
I want to ideally move toward automating this process, so my first step from some Googling was to do this:
rmarkdown::render( "C:/folder1/folder2/test.Rmd", output_format = "html_document", output_file = "test.html", output_dir = "Z:/folder3")
This appears to do what I want, as I no longer need to manually copy and paste/overwrite. However, when I open the file, I find that many of the plots generated from running the above aren't rendering -- (note: the issue doesn't occur when "knitting", only when running the above). Specifically, plots that are generated from the below loop function are not showing... more basic plots elsewhere in the Rmarkdown (without any of the looping logic) are showing just fine.
Is there anything obvious that I am missing? Thanks very much for any help.
for (Spec in UnSpec_SUR) {
Sel <- SES_SPE %>%
filter(Splty == Spec)
cat("\n")
cat("###", Spec, "\n")
x <- ggplot(Sel, aes(WeekStartDate, Used)) +
geom_smooth(fill = "#C1E7FA") +
geom_line(colour = '#595957') +
geom_point(colour = '#F1055B', size = 2) +
geom_vline(aes(xintercept = as.numeric(as.Date("2022-04-04")),
colour = "Financial Year Start"), linetype = 4) +
geom_hline(aes(yintercept = Sel$Allocation, colour = "Allocated"), linetype = 4) +
geom_text(aes(label = round(Used,0)), vjust = -0.8, size = 3, colour = '#F1055B') +
scale_x_date(date_breaks = "1 week",
date_labels = "%d-%b") +
scale_color_manual(name = "", values = c("Allocated" = "#EC950F",
'Financial Year Start' = "forestgreen" )) +
theme_bw() +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1, size = 9),
axis.title.x = element_text(size = 10),
axis.text.y = element_text(vjust = 0.5, size = 9),
axis.title.y = element_text(size =10),
plot.title = element_text(size = 12, face ="bold"),
legend.position = "bottom",
legend.justification = "right",
legend.text = element_text(size = 7),
legend.margin=margin(t=-20)) +
labs(title = Spec, x = 'Week Commencing', y = 'Used')
print(x)
cat("\n")
}