0

I am plotting several graphics in R in a loop and export them as a postscript using postscript().

for(i in 1:length(ind)){
  postscript(names(ind[i]))
  par(mar=c(6,8,6,5))
  plot(ind[[i]][,c('YEAR','VALUE')],
       type='b',
       main=ind[[i]][1,'NAME'],
       xlab="Time [Years]", 
       ylab="Value [mm]")

dev.off()
}

This works all fine but when I have a look at the files in Finder no file extension (e.g .ps) is written to them (I am on Mac OS X 10.8.5). As I want to further process and convert the output images with ImageMagick's mogrify I rely on the file extension. Does anyone have a solution for that? When only plotting one file with postscript() then you specify the filename and the extension but how could this be done in a loop?

Another question: is it possible to incorporate command line tools such as mogrify (http://www.imagemagick.org/script/mogrify.php) into R so that it could be executed from there (a Windows AND Mac solution would be best)?

kurdtc
  • 1,551
  • 5
  • 21
  • 39
  • 1
    I would guess that `ind` doesn't include file names with extension? Paste one together. `paste(names(ind[i]), ".ps", sep = "")`. – Roman Luštrik Sep 04 '14 at 17:42
  • of course! haven't thought about such a simple solution. thank you!! is there a way how I could incorporate command line tools into R? – kurdtc Sep 04 '14 at 19:51

1 Answers1

1

You could add an extension by paste(names(ind[i]), ".ps", sep = ""). If you want to use command line tools, use shell or system.

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197