1

I get Rscript error of:

Error in dev.copy2pdf(file = fname, out.type = "pdf") : can only print from a screen device Execution halted

I am running the following R source in my Mac OSX console with:

Rscript --vanulla charts.R

I am using R version 3.3.2. Here is my source:

library(quantmod)

sym <- 'IBM'    
d <- getSymbols(sym,src = "yahoo", auto.assign = FALSE)

chartSeries(d, name = sym, theme = "white", bar.type = 'ohlc', 
            line.type = "l",TA = "addVo();addSMA()",
            subset = 'last 6 months') 

addRSI()

dev <- dev.prev() 
fname <- sprintf("%s.pdf",sym)
dev.copy2pdf(file = fname, out.type = "pdf")
dev.off()

How do I fix the dev.copy2pdf() if I want to output a PDF running on the conole. It runs fine within my RStudio, Thanks

Gregor de Cillia
  • 7,397
  • 1
  • 26
  • 43
Bryan Downing
  • 207
  • 2
  • 14

1 Answers1

0

This seems to have fixed it

#https://stackoverflow.com/questions/5625394/problem-saving-pdf-file-in-r-with-ggplot2
pdf(fname)
chartSeries(d, name=sym, theme="white",bar.type='ohlc',line.type="l",TA="addRSI();addVo();addBBands();addSMA()",subset='last 6 months')
dev.off()
Bryan Downing
  • 207
  • 2
  • 14
  • It would be helpful to explain exactly how: Do not use `dev.copy2pdf()` or `dev.print()` after compiling the figure, but instead `pdf()` before. – 0range Nov 08 '19 at 14:55