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 -- View this message in context: http://www.nabble.com/Output-results-to-a-single-postscript-document-tp21884901p21884901.html Sent from the R help mailing list archive at Nabble.com.
Pele <drdionc <at> yahoo.com> writes:> 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 > > options (scipen=999, digits=7) > > library(foreign)...> > 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))... Your example is not reproducible because data.csv is not available. And better truncate the list of libraries to the absolute minimum, which is void as I guess. Sometime, problems only turn up because of interactions between libraries. I do not know of a solution with ps, but there is one for pdf, and several alternatives for HTML. See Greg Snow's summary at http://markmail.org/message/yi4w2xmleb6hwcph Dieter
Hi Pele,>> I have been trying to output all my results (text, plots, etc) into the >> same postscript file...Surely I missed something? Is it not simply that you are turning off the postscript device in the wrong place? At the moment you only seem to be using the postscript device in the plotting/chart function. chart <- function(mod) { postscript(file="fig.ps") par(mfrow=c(2,1)) acf(residuals(mod)) pacf(residuals(mod)) dev.off() } ## don't turn it off here Only turn it off when you have finished printing/plotting everything that you want in it. You really do need to be more specific about what you have in mind. Regards, Mark. Pele wrote:> > 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 > >-- View this message in context: http://www.nabble.com/Output-results-to-a-single-postscript-document-tp21884901p21887202.html Sent from the R help mailing list archive at Nabble.com.
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.