[R] Batch mode problem: figure margins too large (code corrected for word wrap)

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu May 12 22:00:08 CEST 2005


Thank you, the word wrap did make it impossible.

For me

pdf(file="c:/CFTC.pdf",height=10,width=8,paper="letter")
## plotting
dev.off()

works in interactive mode or from a file.  I don't understand why you are 
going via dev.print(), nor what exactly what is different about your 
invocation of `batch mode', as putting your commands in file test.R and 
doing

R CMD BATCH test.R
R CMD BATCH --internet2 test.R

also work.  So although I have not nailed the problem I hope I have 
provided some workarounds.

On Thu, 12 May 2005, Lapointe, Pierre wrote:

> First of all, I apologize for the triple post, but I did not see that the
> word wrap on the r-help list site would render my code unusable. So here it
> is again.  Hoping that this time it will work if you cut and paste it in
> your Rgui.
>
> I have a program that works well in Rgui but that does not work in a batch
> file (Execution halted).
>
> Here's the code (it will work on your R, but you need internet access
> through R as it will download a table from a US gov site).
>
> #Code Start
> download.file("http://www.cftc.gov/files/dea/history/deacot2005.zip",
> "c:/deacot2005.zip", "internal", quiet = FALSE, mode = "wb",cacheOK = TRUE)
> unzipped<-zip.file.extract("c:/annual.txt", zipname = "deacot2005.zip")
> #Unzip
> data <-read.table(unzipped, header=TRUE, sep=',')
> windows(height=11,width=8.5)
> z <- layout(matrix(c(1:8), 4,2, byrow = TRUE))
> for (i in 1:8) {  #loop to fill layout
> tbonds<-data[data$'Market.and.Exchange.Names'==
> "U.S. TREASURY BONDS - CHICAGO BOARD OF TRADE ",] #choose only T-Bonds
> ordered<-tbonds[order(tbonds[,3]),]    #order by date
> longb<-ordered[,c(3,9)]
> longb[,1]<-as.Date(longb[,1],format="%Y%m%d") #to transform to date format
> par(mar=c(2.5, 3.5, 2, 4.5)) #need this par for mtext
> plot(longb,type="l",las=1,xlab="",ylab="",bty="l",cex.axis=0.9)
> end<-(longb)[nrow(ordered),]  #mtext text
> end0<-(longb)[nrow(ordered)-1,]   #mtext text
> now<- paste(' Last:',end[,2],"\n",'Prev:',end0[,2])    #mtext text
> mtext(now,side=4, las=2,adj=0,padj=0.5,cex=0.5) #mtext text
> }
> dev.print(pdf, file="c:/CFTC.pdf",height=10,width=8,paper="letter")
> #Code end
>
> As you can see, I need a special par(mar) to make room for the margin text
> (mtext).
>
> When I run this program through a batch file I get this message :
>
> ...
> + longb<-ordered[,c(3,9)]
> + longb[,1]<-as.Date(longb[,1],format="%Y%m%d") #to transform to date format
> + par(mar=c(2.5, 3.5, 2, 4.5)) #need this par for mtext
> + plot(longb,type="l",las=1,xlab="",ylab="",bty="l",cex.axis=0.9)
> + end<-(longb)[nrow(ordered),]  #mtext text
> + end0<-(longb)[nrow(ordered)-1,]   #mtext text
> + now<- paste(' Last:',end[,2],"\n",'Prev:',end0[,2])    #mtext text
> + mtext(now,side=4, las=2,adj=0,padj=0.5,cex=0.5) #mtext text
> + }
> Error in plot.new() : figure margins too large
> Execution halted
>
> I tried to remove the windows(height=11,width=8.5) as I don't need it in
> batch mode, but it prevented the PDF creation as it  " can only print from
> screen device".
>
> dev.print(pdf, file="c:/CFTC.pdf",height=10,width=8,paper="letter")
> Error in dev.print(pdf, file = "c:/CFTC.pdf", height = 10, width = 8,  :
> 	can only print from screen device
> Execution halted
>
> Here's what I have in my windows batch file
>
> Set TZ=GMT
> PATH C:\Program Files\R\rw2010\bin
> Rterm --internet2 --no-restore --no-save <problem.R> result.txt 2>&1
>
> I'm on win2k,
>
>> version
>         _
> platform i386-pc-mingw32
> arch     i386
> os       mingw32
> system   i386, mingw32
> status   Patched
> major    2
> minor    1.0
> year     2005
> month    05
> day      09
> language R
>
> Be nice with me.  I've been a R user for only 2 weeks.
>
> Regards,
>
> Pierre Lapointe
> Assistant Market Strategist
> National Bank Financial
>
>
>
>
> ***********************************************************************************
> AVIS DE NON-RESPONSABILITE:
> Ce document transmis par courrier electronique est destine uniquement a la personne ou a l'entite a qui il est adresse et peut contenir des
> renseignements confidentiels et assujettis au secret professionnel. La
> confidentialite et le secret professionnel demeurent malgre l'envoi de ce
> document a la mauvaise adresse electronique. Si vous n'etes pas le
> destinataire vise ou la personne chargee de remettre ce document a son destinataire, veuillez nous en informer sans delai et detruire ce document ainsi que toute copie qui en aurait ete faite.Toute distribution, reproduction ou autre utilisation de ce document est
> strictement interdite. De plus, le Groupe Financiere Banque Nationale et ses filiales ne peuvent pas etre tenus responsables des dommages pouvant etre causes par des virus ou des erreurs de transmission.
>
> DISCLAIMER:\ This documentation transmitted by electronic ma...{{dropped}}
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list