[BioC] save R graphics device output in a file

Florian Hahne fhahne at fhcrc.org
Mon Apr 14 22:22:37 CEST 2008


I am pretty sure this can not work. AFAIK, savepng uses dev.copy, and in 
a non-interactive R session no (regular) graphics device will be opened 
unless you explicitly ask for that to happen, so there is nothing to 
copy from. You might want to try this in your script:

mat <- rnorm(1000)
png ("testFile.png")
hist(mat)
dev.off()

You also don't need to load the geneplotter or the grDevices packages, 
and also the q("no") is not necessary.
Florian



carol white schrieb:
> Thanks for your reply.
>
> I wrote  a script, namely my_script and run it as
> R < my_script > res --no-save &
>
> my_script contains:
>
> library (geneplotter)
> library (grDevices)
> hist (mat) # mat is a matrix
> savepng ("Rtmp", ".")
> dev.off()
> q("no")
>
> ***********************************3
> so Rtmp.png is created at the end but with 0 byte and res (output 
> file) contains:
> > library (geneplotter)
> > library (grDevices)
> > hist (mat)
> > savepng ("Rtmp", ".")
> [1] "./Rtmp.png"
> > dev.off()
> null device
>           1
> > q("no")
>
>
> but when running in R:
> *****************************
> library (geneplotter)
> Loading required package: annotate
> Loading required package: Biobase
> Loading required package: tools
>
> Welcome to Bioconductor
>
>   Vignettes contain introductory material. To view, type
>   'openVignette()'. To cite Bioconductor, see
>   'citation("Biobase")' and for packages 'citation(pkgname)'.
>
> Loading required package: lattice
> KernSmooth 2.22 installed
> Copyright M. P. Wand 1997
> > library (grDevices)
> > hist (mat)
> > savepng ("Rtmp", ".")
> [1] "./Rtmp.png"
> > dev.off()
> null device
>           1
> > q("no")
>
> ./Rtmp.png is created correctly (a non-zero byte image)
>
> I use R 2.5.1
>
> thanks
>
> */Florian Hahne <fhahne at fhcrc.org>/* wrote:
>
>     Hi Carol,
>     In order to save graphics on a file device you need to properly close
>     this device after the plotting, that is, use dev.off() I am not sure
>     what you mean by "running R in the background". Did you start it
>     via R
>     CMD batch or something similar as a background process? In any case,
>     the proper use of jpeg() and dev.off() should create a valid image
>     file irespective of that, unless you are on remote machine without
>     x11
>     port forwarding, which again should result in a number of errors.
>     Sending a brief example of code that illustrates your problem and at
>     least some information about your R version would also help
>     Cheers
>     Florian
>
>
>
>     On 14.04.2008, at 08:22, carol white wrote:
>
>     > Hi,
>     > I tried to use savepng (library geneplotter) or jpeg (grDevices) to
>     > save the R output image in a file. When I run R in foreground,
>     > savepng saves the image in a file but when I run R in background
>     (in
>     > a unix terminal shell), a file is created but with 0 byte. When the
>     > jpeg is used in R in bg or fg, a file is created with 0 byte.
>     Why is
>     > the image not saved when I run the R in bg?
>     >
>     > Regards,
>     >
>     > carol
>     >
>     >
>     >
>     >
>     >
>     >
>     ____________________________________________________________________________________
>
>
>     > Be a better friend, newshound, and
>     >
>     > [[alternative HTML version deleted]]
>     >
>     > _______________________________________________
>     > Bioconductor mailing list
>     > Bioconductor at stat.math.ethz.ch
>     > https://stat.ethz.ch/mailman/listinfo/bioconductor
>     > Search the archives:
>     http://news.gmane.org/gmane.science.biology.informatics.conductor
>
>
>  
>


-- 
Florian Hahne, PhD
Computational Biology Program
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M2-B876
PO Box 19024
Seattle, Washington 98109-1024
206-667-3148
fhahne at fhcrc.org



More information about the Bioconductor mailing list