wch / extrafont

Tools for using fonts in R graphics
315 stars 48 forks source link

Spaces in filename #20

Closed dougmitarotonda closed 11 years ago

dougmitarotonda commented 11 years ago

Hi, I would find it extremely helpful if embed_fonts was able to use filenames that have spaces in them. See the example below. Thanks, Doug

Example

m <- mtcars[1:10,] p <- ggplot(m, aes(x = wt, y = mpg, color = hp)) + geom_point()

Works

filename <- "~/Desktop/foo.pdf" ggsave(filename, p) embed_fonts(filename)

Does not work

filename <- "~/Desktop/foo 2.pdf" ggsave(filename, p) embed_fonts(filename) Error: /undefinedfilename in (/Users/dougmitarotonda/Desktop/foo) Operand stack:

Execution stack: %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval-- 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- false 1 %stopped_push Dictionary stack: --dict:1156/1684(ro)(G)-- --dict:0/20(G)-- --dict:77/200(L)-- Current allocation mode is local Last OS error: 2 GPL Ghostscript 9.05: Unrecoverable error, exit code 1 Error in embedFonts(file = file, format = format, outfile = outfile, options = paste(paste("-I", : status 1 in running command 'gs -dNOPAUSE -dBATCH -q -dAutoRotatePages=/None -sDEVICE=pdfwrite -sOutputFile=/var/folders/tc/6t_2yc616dz74f9zpf8cy_hm0000gp/T//Rtmp5ea4Fc/Rembed7a00addeece -sFONTPATH= -I'/Users/dougmitarotonda/R/extrafontdb/fontmap' ~/Desktop/foo 2.pdf'

wch commented 11 years ago

I think this is due to a bug in the embedFonts function (from grDevices), which is called by embed_fonts:

library(ggplot2)
qplot(1:3, 1:3)
ggsave('foo 2.pdf')

embedFonts('foo 2.pdf')  # Error

But it looks like you can make it work if you put quotes in the filename (this makes the output format auto-detection fail, so you also need to specify the output format).

embedFonts("'foo 2.pdf'", format="pdfwrite")
wch commented 11 years ago

Fixed in 3dbbbc7049612037881d1984d6c1710c0381eec6.

mlt commented 11 years ago

Is it time to remove enquoting? It looks like original bug has been fixed. Now I'm getting an error that file with extra single quotes can't be found.

wch commented 11 years ago

Hm, this will have to be done with an R version check. Something like this:

if (getRversion() <= numeric_version("2.15.2")) {
  # Add quotes (or perhaps use shQuote)
}

@mlt if I push a branch with this modification, could you test it on your system for me? I don't have the development version of R installed.

mlt commented 11 years ago

I don't have the development version of R installed.

I don't know what was actually going on with my installation as I'm also using stable 2.15.2 (under MS Windows). I suspect it might be related to GS update as I might have used 8.63 and when I moved to 9.05 (and 9.06) it did not like single quotes.

First time I though grDevices package was updated along with other updates I installed. But it looks like it is not the case.

Long story short... perhaps I had another issue that recent version of GS does not like single quotes under MS Windows. With shQuote in your development branch it works.

wch commented 11 years ago

I'm going to revert the version check part. I had assumed that you were using the development version of R, since the embedFonts bug was fixed only a week or two ago and you suggested that it was causing new problems.

mlt commented 11 years ago

you suggested that it was causing new problems

I did not. With you version as is, it works.

I do not even have spaces in file names, only underscores. I was just surprised why previous installation suddenly quit working. I though grDevices could be updated independently from the rest. I thought I was using 2.15.2 with newer grDevices. But now I tend to think that single quotes were passed as is to GS and newer version was not happy about it.