I have the need to build a function that will plot multiple pdfs, read them in, combine the results (different sized pdfs), save the combined file and delete the initial files. I’m getting hung up on the initial part of interactively plotting multiple plots to external pdfs. The problem is I need a way of pausing in the for loop, waiting for the plot and then moving on after receiving the plot. I thought readLines was the way to go (and it may be) but this did not work (i.e. no plot was produced).
How can I make R pause between pdf take the plot, move onto dev.off and reiterate through the process again? The desired outcome is to have three files in the wd called file1.pdf, file2.pdf and file3.pdf. Again, after running the loop/lapply, this process will be interactive.
This is a MWE of the problem:
widths <- c(10, 9, 8)
heights <- c(11, 9, 7)
file <- "foo.pdf"
lapply(1:3, function(i) { #will askfor/take 3 plots interactively
qo <- gsub(".pdf", paste0(i, ".pdf"), file, fixed = TRUE)
cat("plot now...")
pdf(file=qo, width = widths[i], height = heights[i])
#pause command here
dev.off()
})
#the interactive part
plot(1:10)
plot(1:13)
plot(1:15)
EDIT 1 Related question: Determine ghostscript version
EDIT 2 Here’s a link to the package I used this information to create -click here-
Is it as simple as this?
This stops to read a single line from
stdin, i.e. the console. Press Enter to carry on.