0

I saved two figures by the following functions. However, I can not open any of them. The error message is "The file can not be opened because something keeps it from opening"

#
starttest()

starttest <- function() {
  helperfunction("1")

  helperfunction("2")
}

helperfunction<- function(i) {
  dat = data.frame(x = c(1:10), y = c(2:11)) 

  pdf(paste(i,'figure1.pdf',sep = ""))
  ggplot(data = dat, aes(x = x, y = y)) + geom_step()
  dev.off()
}
#

However, if I run the following code by selecting the code and hit "Ctrl R", the two pdfs can be opened

#
dat = data.frame(x = c(1:10), y = c(2:11)) 

 pdf(paste(1,'figure1.pdf',sep = ""))
 ggplot(data = dat, aes(x = x, y = y)) + geom_step()
 dev.off()

 pdf(paste(2,'figure1.pdf',sep = ""))
 ggplot(data = dat, aes(x = x, y = y)) + geom_step()
 dev.off()
#

So, as long as the figure is saved in a function called by the main function, I can not open the figure.....

nimning
  • 527
  • 1
  • 5
  • 5

0 Answers0