Re: [R] Making TIFF images with rtiff

From: Inman, Brant A. M.D. <Inman.Brant_at_mayo.edu>
Date: Fri 12 Jan 2007 - 18:17:49 GMT

Several R Helpers pointed out that I forgot to include the dev.off() statement in my code. This solved my problem with one caviat: the output file address cannot have any spaces in it (as pointed out by Chuck Cleland). For instance:



# This file location works great
bitmap(file='C:\\temp\\test.tif',

        type = "tifflzw", res = 1200)
plot(speed ~ dist)
dev.off()

# This file location does not work, despite being accurate bitmap(file='C:\\Documents and Settings\\m007704\\Desktop\\test.tif',

        type = "tifflzw", res = 1200)
plot(speed ~ dist)
dev.off()


For the benefit of those that may need to make TIFF files in the future and don't know how to do it, I will recapitulate below the steps required to produce a TIFF file using R on a Windows XP machine.

  1. Download and install a current version of Ghostscript.

You probably need GPL(GNU General Public License) version of Ghostscript. For Windows, the correct file to download is called: gs854w32-gpl.exe. To download this file, go to one of the following websites:

http://www.cs.wisc.edu/~ghost/
http://sourceforge.net/projects/ghostscript/

2) Add Ghostscript to a Windows environmental variable.

Right click on the My Computer icon on your desktop. Select: Properties
> Advanced > Environmental Variables. You will see 2 boxes, one for
user variables and one for system variables. In the user variables section, highlight the variable called "PATH" and then click edit. Click on the variable value box and go to the end of whatever is written there (don't erase it). Enter the following after the last bit of text: ";C:\Program Files\gs\gs8.54\bin\". This is the location on you computer where it can find the gswin32c.exe file that it needs to start Ghostscript.

3) Use the bitmap function to produce a TIFF

Now you should be ready to make a TIFF. The following code is a simple example that you can use to see if everything is set up right on your PC.

attach(cars)
bitmap(file='C:\\temp\\test.tif',

        type = "tifflzw", res = 1200)
plot(speed ~ dist)
dev.off()

This should produce a TIFF file called 'test.tif' in the 'temp' directory of your PC. If you do not have a directory of this name, substitute for one that exists (or create one). Note that the file argument does not seem to handle and spaces in the directory address, so select an address without spaces in it. Note also that, as pointed out by Ripley in this thread, there are different TIFF formats which can be made with R. My understanding is that the different formats have to do with different image compression algorithms, but you can read more about these details (and clues to why TIFF files seem to be prefered by some publishers and imaging software makers) at:

http://en.wikipedia.org/wiki/Comparison_of_graphics_file_formats

You can also type ?bitmap to see what R can output for you and read more about the TIFF file format at:

http://en.wikipedia.org/wiki/Tiff

I regret that I cannot comment on Unix or Mac computers as it has been nearly 15 years since I have used these types of machines and I therefore have no knowledge whatsoever that might be of use for users of these systems.

Brant Inman



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 and provide commented, minimal, self-contained, reproducible code. Received on Sat Jan 13 05:26:10 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Fri 12 Jan 2007 - 19:31:33 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.