9

I'm trying to save an SVG image to a file path containing Unicode characters. For example:

n = c(2, 3, 5)
s = c("aa", "bb", "cc") 
b = c(TRUE, FALSE, TRUE) 
df = data.frame(n, s, b)

svg("c:/נועם/plots.svg")
plot(df)
dev.off() 

Running this with Rscript.exe fails with the following error:

Error in plot.new() : cairo error 'error while writing to output stream'

How can I make it work?

Artem
  • 3,304
  • 3
  • 18
  • 41
Noam Behar
  • 201
  • 2
  • 11
  • 2
    Looks like a Windows issue. –  Jan 06 '16 at 09:23
  • 3
    I would suggest not creating directory names in Hebrew in the first place. From my experience, working solely in English is the safest practice in order to avoid such and many other potential issues in general. – David Arenburg Jan 06 '16 at 10:46
  • Also, see what happens when you do `normalizePath("c:/נועם/plots.svg")` – David Arenburg Jan 06 '16 at 10:55
  • Hebrew was just given as an example. The script attempts to write to the user local folder (c:/users/), and when the account username contain Unicode characters, I hit this bug. – Noam Behar Jan 06 '16 at 12:24
  • 2
    @NoamBehar as a Sysadmin I will back up David's advice, don't use anything else than ascii letters. User names with unicode will lead to problems, home dirs are a pain to manage, permissions on NTFS will sometimes hang, etc. To fix your script, write elsewhere than user's home. If security/permissions are an issue, manage them instead of relying on a 'should be' state of the file at end as it can't be guaranteed in anyway. – Tensibai Jan 06 '16 at 12:56
  • I second the motion that is an OS bug. – Rick James Jan 17 '18 at 21:20

2 Answers2

0

You can set working directory to the directory with Hebrew name than save svg file. Please see the code below:

n <- c(2, 3, 5)
s <- c("aa", "bb", "cc") 
b <- c(TRUE, FALSE, TRUE) 
df <- data.frame(n, s, b)
setwd("C:\\נועם\\")
svg("plots.svg")
plot(df)
dev.off() 
Artem
  • 3,304
  • 3
  • 18
  • 41
0

Late to the party but I think that wrapping the path in enc2native() function normally solves encoding issues under Windows to my experience. In your case you should try

svg(enc2native("c:/נועם/plots.svg"))
eastclintw00d
  • 2,250
  • 1
  • 9
  • 18