[R] Batch mode problem: figure margins too large

From: Lapointe, Pierre <Pierre.Lapointe_at_nbf.ca>
Date: Fri 13 May 2005 - 03:38:33 EST


Hello, 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 you side, but you need internet access through R as it will download a table from a US gov site)         

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")

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 :

...

> 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
		+ }
		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
1155 Metcalfe Street, 5th Floor
Montreal (Qc)
H3B 4S9
(514) 879-2378



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@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 Received on Fri May 13 03:46:50 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:45 EST