[Gretl-users] R & Gretl: Accented file names problem

Allin Cottrell cottrell at wfu.edu
Tue Jan 28 22:27:44 EST 2014


On Tue, 28 Jan 2014, Henrique wrote:

> I think I found a problem with accented path or directory names 
> using R and Gretl. Look at the simple code:
>
> <hansl>
>
> nulldata 1

Incidentally, why that line?

> # Works fine when the directory has
> # no accented filename ("Teste")
> foreign=R
>    nome_da_serie <- file("C:/Users/henrique/Documents/gretl/Teste/Nome.txt")
>    nome_da_serie <- readLines(nome_da_serie, n = 1)
>    nome_da_serie
> end foreign
>
> # Doesn't work when the directory
> # has accented filename ("Téstê")
> # Gretl freezes
> foreign=R
>    nome_da_serie <- file("C:/Users/henrique/Documents/gretl/Téstê/Nome.txt")
>    nome_da_serie <- readLines(nome_da_serie, n = 1)
>    nome_da_serie
> end foreign
>
> # Doesn't work when the file
> # doesn't exist ("Name.txt")
> # Gretl freezes
> foreign=R
>    nome_da_serie <- file("C:/Users/henrique/Documents/gretl/Teste/Name.txt")
>    nome_da_serie <- readLines(nome_da_serie, n = 1)
>    nome_da_serie
> end foreign
>
> </hansl>
>
> Using the commands directly on R works fine.

This works fine in both cases on Linux or Mac, because everyone is 
talking the same language (well, encoding): gretl, R, and the 
operating system all speak UTF-8.

I suspect that what's happening on Windows is this:

1) You type the accented characters in gretl's script editor, which 
is a GTK widget and always uses UTF-8.

2) Gretl ships out your UTF-8 encoded "foreign" lines to R.

3) R tries tries to open your file using a UTF-8 encoded path and 
fails because Windows doesn't do UTF-8.

If that's right, I don't think there's anything we can do about it. 
Here's the problem.  If gretl wants to open a file itself, based on 
a name typed into the script editor, it knows that it may have to 
recode the path on Windows (ugh, boo!) and is prepared for that 
eventuality. But if gretl is shipping "foreign" lines out to another 
program, we don't know what those lines mean (we don't and can't 
parse them) and we really have no idea if it would make sense to 
recode them to the Windows locale.

Moral: don't try to use non-ASCII characters in a gretl "foreign" 
block on MS Windows unless you happen to know that the target 
program will handle UTF-8 properly.

Allin



More information about the Gretl-users mailing list