[R] automatically jpeg output

(Ted Harding) ted.harding at nessie.mcc.ac.uk
Fri Jul 20 18:07:38 CEST 2007


On 20-Jul-07 15:34:00, Ding, Rebecca wrote:
> Dear R users,
> 
> I used R to draw many histograms and I would like to automatically save
> them into a jpeg file. I tried the following code since I know .ps file
> could be saved like this way:
> 
> postscript("AYA_ELA.jpeg",horizontal=F,onefile=T)
> ......#some funtions inside here
> dev.off()
> 
> There was a jpeg file, however, there is no pictures inside. Any
> suggestion? 
> 
> Thanks.
> 
> Rebecca

If your "some functions inside here" do draw histograms, then
there will indeed be pictures inside, but they will be in PostScript,
since that is what is created when you use the postscript() device.
The fact that you used ".jpeg" in the fileneam has nothing to
do with it -- it will simply store the output, as PostScript,
in the file whose name you give to it. It trusts you.

You would have seen the PostScript pictures if you had used a
PostScript viewer which reacts to the content of the files,
whereas presumably your system expects a file whose name ends
in ".jpeg" or ".jpg" to be a JPEG file; and therefore will
use the wrong interpreter and fail to recognise the picture
(as you have just proved).

If you want to create JPEG files in a similar way, use the
jpeg() function -- read ?jpeg for details.

Best wishes,
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 20-Jul-07                                       Time: 17:07:20
------------------------------ XFMail ------------------------------



More information about the R-help mailing list