0

I need to export around 100 graphs in a pdf everyday. I want to make a function to combine multiple functions into a single function so I can run it easily everyday Following is my function, chartSeries95 mean 95 different object (not in order...)

chartSeries95 <- 
function(x,y) {
pdf (file=paste(format(Sys.time(), "%Y-%m-%d %I-%p"), "pdf", sep = "."))
chartSeries(`H0001_xts`, theme="white", TA="addVo();addBBands();addCCI();addRSI();addMACD()", subset='last x weeks')
chartSeries(`H0001_xts`, theme="white", TA="addVo();addBBands();addCCI();addRSI();addMACD()", subset='last y weeks')
...    
dev.off()
}

In the above example, I need to plot the same object for two different parameters x,y. My ideal output is I can view hundreds of stocks in a single pdf file (with the name like this, YYYY-MM-DD.pdf) with different time periods x,y. Thanks.

tw123789
  • 55
  • 11
  • expand on `...` bit of your example, I can see only 2 types of plots at the moment. What other plots are there? If there is a pattern in plot code, then it can be run within a loop. – zx8754 May 28 '15 at 05:47
  • I would use knitr for this, see for example this thread: http://stackoverflow.com/questions/15396755/using-loops-with-knitr-to-produce-multiple-pdf-reports-need-a-little-help-to or you can use sweave, see this thread: http://stackoverflow.com/questions/8519128/can-sweave-produce-many-pdfs-automatically?lq=1 – grrgrrbla May 28 '15 at 07:24
  • @zx8754 how to use the loop? because the numbers are not in sequential pattern, for example, H0001 is followed by H0004, H0007, H0009 etc. rather than H0002, H0003, H0004...Please kindly help. – tw123789 May 31 '15 at 16:23
  • @grrgrrbla, I have tried to use knitr. I put the chartseries function under the section of plot. ```{r, echo=FALSE} (`H0001_xts`, theme="white", TA="addVo();addBBands();addCCI();addRSI();addMACD()", subset='last x weeks') ``` it returned `could not find function "chartSeries" Calls: ... handle -> withCallingHandlers -> withVisible -> eval -> eval Execution halted` But I have already "tick" the package in Rstudio. – tw123789 May 31 '15 at 17:29
  • @grrgrrbla, I know how to use knitr now, it is a good lesson to learn...Thanks. – tw123789 Jun 01 '15 at 08:58
  • I am glad it helped, I struggled a lot with using for loops in knitr in the beginning as well, but once it works it saves you a lot of time /work, and you can do a lot of stuff with it, besides its always better to learn how to fish than to ask for a fish :), grats for pushing through the troubles yourself! – grrgrrbla Jun 01 '15 at 09:03

0 Answers0