[R] Output results to a single postscript document

Pele drdionc at yahoo.com
Sat Feb 7 14:16:12 CET 2009


Hello R users,

Below is the code and output of what I am trying to do.  My goal is to
insert/print all items in the chart function into a pdf document. Only the
acf and pacf charts gets printed.

Again, thanks in advance for any help I can get!

####################################
options (scipen=999, digits=7)

library(lmtest)
library(dyn)

tdata <- ts(read.table("C:/test/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))
        
	  chart <- function(mod) {
	  pdf(file="results.pdf")
   	  par(mfrow=c(2,1)) 
   	  acf(residuals(mod)) 
   	  pacf(residuals(mod)) 
          summ<- summary(mod)
	  aic	<- AIC(mod)
    	  dev.off()                }
	  				                                  	
	  output  <- return(list(Charts=chart(mod))) }
	  results <- res(tdata[ ,"Y"], tdata[ ,"X_VARY"]) ; results

############output###############

> options (scipen=999, digits=7)
> 
> library(lmtest)
> library(dyn)
> 
> tdata <- ts(read.table("C:/test/data.csv" ,sep = ",",header=TRUE))
>  print(tdata)
Time Series:
Start = 1 
End = 20 
Frequency = 1 
   Unit  Y X_VARY  K D_WAY
 1    1  3      2  4    50
 2    2  5      3  9    50
 3    3  6     11 22    50
 4    4  8      4  7     2
 5    5  9     11 11     2
 6    6 12     13 13     2
 7    7 23     25 12     2
 8    8 22     30 31     3
 9    9 23      3  3     3
10   10 19     21 21    32
11   11  3      2  4    34
12   12  5      3  9     4
13   13  6     11 22     4
14   14  8      4  7     4
15   15  9     11 11     4
16   16 12     13 13     4
17   17 23     25 12     4
18   18 22     30 31     4
19   19 23      3  3     4
20   20 19     21 21     5
> 
>    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))
+         
+   chart <- function(mod) {
+   pdf(file="results.pdf")
+      par(mfrow=c(2,1)) 
+      acf(residuals(mod)) 
+      pacf(residuals(mod)) 
+         summ<- summary(mod)
+   aic<- AIC(mod)
+       dev.off()                }
+                                     
+   output  <- return(list(Charts=chart(mod))) }
> 
>   results <- res(tdata[ ,"Y"], tdata[ ,"X_VARY"]) ; results
$Charts
null device 
http://www.nabble.com/file/p21888211/results.pdf results.pdf 


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..

[[elided Yahoo spam]]



http://www.nabble.com/file/p21888211/data.csv data.csv 
-- 
View this message in context: http://www.nabble.com/Output-results-to-a-single-postscript-document-tp21884901p21888211.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list