Skip to content
Prev 169589 / 398502 Next

Output results to a single postscript document

Hello R users,

I have been trying to output all my results (text, plots, etc) into the same
postscript file as 

one document, but have been unable to...Can anyone help me improve my code
below so that I can 

accomplish this?  Currently I have to output them separately then piece them
back together into 

one document..

Thanks in Advance for any help!


options (scipen=999, digits=7)

library(foreign)
library(Hmisc)
library(prettyR)
library(DAAG)
library(lmtest)
library(car)
library(MASS)
library(nlme)
library(dyn)
library(wle)
library(lasso2)
library(zoo)

tdata <- ts(read.table("C:/tmp/data.csv" ,sep = ",",header=TRUE))
 print(tdata)

   res 	<- function(dep, indep, fn, env = parent.frame()) {
   depnm   	<- deparse(substitute(dep))
   indepnm 	<- deparse(substitute(indep))
        fo 	<- sprintf("%s ~ lag(%s, -1) + %s", depnm, depnm, indepnm)
        fo 	<- as.formula(fo, env = env)
        mod <- do.call(dyn$lm, list(fo))
        summ<- summary(mod)

	  chart <- function(mod) {
	  postscript(file="fig.ps")
   	  par(mfrow=c(2,1)) 
   	  acf(residuals(mod)) 
   	  pacf(residuals(mod)) 
   	  dev.off()                }
	  				                                  	
	  output  <- return(list(Summary=summ, Chart=chart(mod))) }
						
	  results <- res(tdata[ ,"Y"], tdata[ ,"X_VARY"]) ; results