pharmaverse / tidytlg

The goal of tidytlg is to generate tables, listings, and graphs (TLG) using Tidyverse.
https://pharmaverse.github.io/tidytlg/
Other
33 stars 6 forks source link

gentlg doesn't work for multiple graphs #13

Closed shengwei66 closed 1 year ago

shengwei66 commented 1 year ago

Users have reported that an error is encountered in gentlg when creating the output for multiple graphs. The reprex is below.

Prep Environment

library(dplyr) library(ggplot2) library(tidytlg)

adsl <- cdisc_adsl %>% filter(SAFFL == "Y")

tblid <- "test2plots"

Generate Results

plot1 <- ggplot(data = adsl, aes(x = HEIGHTBL, y = WEIGHTBL)) + geom_point() + labs(x = "Baseline Height (cm)", y = "Baseline Weight (kg)")

create png file of plot1

png("../output/plot1.png", width=2800, height=1800, res=300, type = "cairo")

plot1

dev.off()

plot2 <- ggplot(data = adsl, aes(x = WEIGHTBL, y = HEIGHTBL)) + geom_point() + labs(x = "Baseline Weight (kg)", y = "Baseline Height (cm)")

create png file of plot2

png("../output/plot2.png", width=2800, height=1800, res=300, type = "cairo")

plot2

dev.off()

Output Results

gentlg(tlf = "g", plotnames = paste0("../output/", c("plot1.png","plot2.png")), opath = "../output", plotwidth = 8, plotheight = 5, orientation = "landscape", file = tblid, title = "Scatter plot")

Error in if (file.exists(plotnames)) { : the condition has length > 1

This used to work in previous version without error.