[R] dev.off and Cairo and ggplot2

2011-07-13 Thread Stephen Eick
I have a weird example which fails and I don't understand why.  If I
put dev.off() inside my function, it produces a bad image file.  But
if I run what I think should be equivalent code with dev.off() running
outside my function, it works.  Why does the location of dev.off
matter?


library(Cairo)
library(ggplot2)

foo-function(){
   Cairo(file=a.png)
   cat(dev.cur(), \n)
   qplot(1:10,1:10)
   dev.off();
}

foo()

# file a.png is bad

foo1-function(){
   Cairo(file=a.png)
   cat(dev.cur(), \n)
   qplot(1:10,1:10)
}

foo1(); dev.off()

# file a.png is good

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] dev.off and Cairo and ggplot2

2011-07-13 Thread David Winsemius


On Jul 13, 2011, at 5:55 PM, Stephen Eick wrote:


I have a weird example which fails and I don't understand why.  If I
put dev.off() inside my function, it produces a bad image file.  But
if I run what I think should be equivalent code with dev.off() running
outside my function, it works.  Why does the location of dev.off
matter?


It's in the misc section of the R-FAQ:

(Title is something along the lines of Why don't lattice plots show  
up? but its more general than lattice and also applies to ggplot/ 
ggplot2)


--
David.




library(Cairo)
library(ggplot2)

foo-function(){
  Cairo(file=a.png)
  cat(dev.cur(), \n)
  qplot(1:10,1:10)
  dev.off();
}

foo()

# file a.png is bad

foo1-function(){
  Cairo(file=a.png)
  cat(dev.cur(), \n)
  qplot(1:10,1:10)
}

foo1(); dev.off()

# file a.png is good

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


David Winsemius, MD
West Hartford, CT

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] dev.off(): is there a 'quiet'-mode?

2010-05-12 Thread Marius Hofert
Dear R experts,

On shutting down a device with dev.off(), the number and name of the new active 
device is returned/printed. How can this be prevented from being shown? Is 
there something like a 'quiet'-mode?

Cheers,

marius
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] dev.off(): is there a 'quiet'-mode?

2010-05-12 Thread Duncan Murdoch

On 12/05/2010 6:09 PM, Marius Hofert wrote:

Dear R experts,

On shutting down a device with dev.off(), the number and name of the new active 
device is returned/printed. How can this be prevented from being shown? Is 
there something like a 'quiet'-mode?
Like any other expression, if you assign the result to a variable, it 
won't be printed.  So


x - dev.off()

would work.

If you don't want to waste a variable name, you can achieve the 
non-printing by wrapping the call in invisible():


invisible(dev.off())

will return the result with printing turned off.

Duncan Murdoch

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] dev.off(): is there a 'quiet'-mode?

2010-05-12 Thread Ted Harding
On 12-May-10 22:09:18, Marius Hofert wrote:
 Dear R experts,
 On shutting down a device with dev.off(), the number and name of the
 new active device is returned/printed. How can this be prevented from
 being shown? Is there something like a 'quiet'-mode?
 
 Cheers,
 marius

I don;t know about a specific quiet mode, but try the following:

  Dev.Off -function(which=dev.cur()){ dummy-dev.off(which) }
  X11() ## Or whatever you use to get a new window
  Dev.Off()

Ted.


E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
Fax-to-email: +44 (0)870 094 0861
Date: 12-May-10   Time: 23:21:36
-- XFMail --

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] dev.off() inside a function other glitches

2008-07-02 Thread Michael Hopkins


Thanks to all who replied on list and to me directly.

You are right, FAQ 7.22 is the answer.  For any others who get caught  
by this it's important to print(..) a plot with a function, not just  
create it, i.e.


print( xyplot(...   ) )

not just

xyplot(... )

..otherwise it doesn't necessarily get sent to the opened device.

Michael


On 2 Jul 2008, at 01:06, Deepayan Sarkar wrote:

On 7/1/08, Michael Hopkins [EMAIL PROTECTED]  
wrote:



Hi R people

I am using a function to create a pdf device, then send a lot of  
plots

to it in a loop then a last lattice xyplot (itself within a function)
outside the loop and finally call dev.off() to write to the file.
This works well apart from the fact that the last plot does not get
sent to the file unless I comment out dev.off() and then apply it in
the console afterwards instead:

   plot_stuff( ...); dev.off()

The device is opened like this:

   pdf( paste( var_string, .pdf, sep= ), onefile=TRUE,  
paper=a4r,

width=9, height=6.5 )

Also, if I try to send two different xyplots after the loop only the
last one ever gets written to the file, whether or not I apply the
dev.off() trick above.

Any thoughts on why this stuff happens and best ways to avoid it are
appreciated.


This sounds like FAQ 7.22:

http://cran.us.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f

The dev.off() issue is most likely a red herring; the important bit is
that the xyplot() call was not the last expression in your function.

-Deepayan





Web:http://www.hopkins-research.com/
 Office:+44 (O)1732 228844
 Mobile:+44 (O)7813 467381

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] dev.off() inside a function other glitches

2008-07-01 Thread Michael Hopkins


Hi R people

I am using a function to create a pdf device, then send a lot of plots  
to it in a loop then a last lattice xyplot (itself within a function)  
outside the loop and finally call dev.off() to write to the file.   
This works well apart from the fact that the last plot does not get  
sent to the file unless I comment out dev.off() and then apply it in  
the console afterwards instead:

plot_stuff( ...); dev.off()

The device is opened like this:

pdf( paste( var_string, .pdf, sep= ), onefile=TRUE, paper=a4r,  
width=9, height=6.5 )

Also, if I try to send two different xyplots after the loop only the  
last one ever gets written to the file, whether or not I apply the  
dev.off() trick above.

Any thoughts on why this stuff happens and best ways to avoid it are  
appreciated.

Other info - R 2.7.1 on Intel Mac 10.5.3.

TIA

Michael

__

 Hopkins Research  Touch the Future
__


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] dev.off() inside a function other glitches

2008-07-01 Thread Duncan Murdoch

Michael Hopkins wrote:

Hi R people

I am using a function to create a pdf device, then send a lot of plots  
to it in a loop then a last lattice xyplot (itself within a function)  
outside the loop and finally call dev.off() to write to the file.   
This works well apart from the fact that the last plot does not get  
sent to the file unless I comment out dev.off() and then apply it in  
the console afterwards instead:


plot_stuff( ...); dev.off()
  
dev.off() shouldn't care where it is being called from.  Please post 
(short!) reproducible code to show your glitch.


Duncan Murdoch

The device is opened like this:

	pdf( paste( var_string, .pdf, sep= ), onefile=TRUE, paper=a4r,  
width=9, height=6.5 )


Also, if I try to send two different xyplots after the loop only the  
last one ever gets written to the file, whether or not I apply the  
dev.off() trick above.


Any thoughts on why this stuff happens and best ways to avoid it are  
appreciated.


Other info - R 2.7.1 on Intel Mac 10.5.3.

TIA

Michael

__

 Hopkins Research  Touch the Future
__


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] dev.off() inside a function other glitches

2008-07-01 Thread jim holtman
Are you explicitly 'print'ing the lattice plot?

print(xyplot(...))



On Tue, Jul 1, 2008 at 6:20 AM, Michael Hopkins
[EMAIL PROTECTED] wrote:


 Hi R people

 I am using a function to create a pdf device, then send a lot of plots
 to it in a loop then a last lattice xyplot (itself within a function)
 outside the loop and finally call dev.off() to write to the file.
 This works well apart from the fact that the last plot does not get
 sent to the file unless I comment out dev.off() and then apply it in
 the console afterwards instead:

plot_stuff( ...); dev.off()

 The device is opened like this:

pdf( paste( var_string, .pdf, sep= ), onefile=TRUE, paper=a4r,
 width=9, height=6.5 )

 Also, if I try to send two different xyplots after the loop only the
 last one ever gets written to the file, whether or not I apply the
 dev.off() trick above.

 Any thoughts on why this stuff happens and best ways to avoid it are
 appreciated.

 Other info - R 2.7.1 on Intel Mac 10.5.3.

 TIA

 Michael

 __

 Hopkins Research  Touch the Future
 __


[[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.




-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] dev.off()

2007-11-21 Thread amna khan
Dear Sir

Sir when I use png function to save graph. At last it is written dev.off().
it does not produce any postscript file.

Please help in this regard



Thank you

-- 
AMINA SHAHZADI
Department of Statistics
GC University Lahore, Pakistan.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] dev.off()

2007-11-21 Thread Chung-hong Chan
png function is used for producing png format (Portable Network
Graphics) of image.
you need to use the postscript() function to generate a ps graph.

Refer to:
http://stat.ethz.ch/R-manual/R-patched/library/grDevices/html/postscript.html


On 11/22/07, amna khan [EMAIL PROTECTED] wrote:
 Dear Sir

 Sir when I use png function to save graph. At last it is written dev.off().
 it does not produce any postscript file.

 Please help in this regard



 Thank you

 --
 AMINA SHAHZADI
 Department of Statistics
 GC University Lahore, Pakistan.

 [[alternative HTML version deleted]]

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.



-- 
CH Chan
Research Assistant - KWH
http://www.macgrass.com

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.