save R graphics device output in a file
1
0
Entering edit mode
carol white ▴ 680
@carol-white-2174
Last seen 8.8 years ago
European Union
An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/bioconductor/attachments/20080414/ 3ad1da93/attachment.pl
• 1.0k views
ADD COMMENT
0
Entering edit mode
Florian Hahne ▴ 540
@florian-hahne-2471
Last seen 9.6 years ago
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 <wht_crl at="" yahoo.com=""> 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
ADD COMMENT
0
Entering edit mode
An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/bioconductor/attachments/20080414/ e75b104d/attachment.pl
ADD REPLY
0
Entering edit mode
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
ADD REPLY
0
Entering edit mode
On Mon, Apr 14, 2008 at 4:01 PM, carol white <wht_crl at="" yahoo.com=""> wrote: > 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") Try: png('stuff.png') hist(mat) dev.off() > ***********************************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 > > > > [[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 >
ADD REPLY
0
Entering edit mode
An embedded and charset-unspecified text was scrubbed... Name: not available Url: https://stat.ethz.ch/pipermail/bioconductor/attachments/20080414/ 58e378ca/attachment.pl
ADD REPLY

Login before adding your answer.

Traffic: 838 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6