[R] latin1 encoding in WriteXLS

Rainer Hurling rhurlin at gwdg.de
Sun Aug 18 10:09:54 CEST 2013


[maintainer CC'ed]


Am 17.08.2013 11:28, schrieb Hugo Varet:
> Yes, it also occurs with WriteXLS version 3.2.1.
> 
> This test on several computers always leads to the same error.

Oops, sorry. I just realised that this happens on both Windows and Unix
alikes. On Win7 I am using ActivePerl 5.16.3 (X64).

The relevant perl scripts (WriteXLS.pl and Encode.pm) seem to be the
same on Unix/Linux and on Windows.

The first lines of the temporary file '1.csv', from which the xls should
be created, looks like:

"Sepal.Length","Sepal.Width","Petal.Length","Petal.Width","Species"
"WRITEXLS COMMENT: ","WRITEXLS COMMENT: ","WRITEXLS COMMENT: ","WRITEXLS
COMMENT: ","WRITEXLS COMMENT: "
"5.1","3.5","1.4","0.2","setosa"
"4.9","3","1.4","0.2","setosa"
"4.7","3.2","1.3","0.2","setosa"
"4.6","3.1","1.5","0.2","setosa"
"5","3.6","1.4","0.2","setosa"
"5.4","3.9","1.7","0.4","setosa"
"4.6","3.4","1.4","0.3","setosa"
"5","3.4","1.5","0.2","setosa"
"4.4","2.9","1.4","0.2","setosa"
"4.9","3.1","1.5","0.1","setosa"
"5.4","3.7","1.5","0.2","setosa"
"4.8","3.4","1.6","0.2","setosa"
"4.8","3","1.4","0.1","setosa"
[..]


The sequence to call the converting perl script from WriteXLS by
system() is:

cmd <- paste(perl, " -I", shQuote(Perl.Path), " ", shQuote(Fn.Path),
    " --CSVPath ", shQuote(Tmp.Dir), " --verbose ", verbose,
    " --AdjWidth ", AdjWidth, " --AutoFilter ", AutoFilter, "
--BoldHeaderRow ",
    BoldHeaderRow, " --FreezeRow ", FreezeRow, " --FreezeCol ",
    FreezeCol, " --Encoding ", Encoding, " ", shQuote(ExcelFileName),
    sep = "")


WriteXLS is calling the perl code by 'Result <- system(cmd)':

"perl -I'/usr/local/lib/R/library/WriteXLS/Perl'
'/usr/local/lib/R/library/WriteXLS/Perl/WriteXLS.pl' --CSVPath
'/tmp/RtmpFpgjq6/WriteXLS' --verbose FALSE --AdjWidth FALSE --AutoFilter
FALSE --BoldHeaderRow FALSE --FreezeRow 0 --FreezeCol 0 --Encoding
latin1 '/usr/home/rhurlin/iris.xls'"


In Perl, '/usr/local/lib/R/library/WriteXLS/Perl/WriteXLS.pl' is calling
'/usr/local/lib/R/library/WriteXLS/Perl/Encode.pm' to decode the csv
file (in this case iso8859-1) and encode again in uft8, if needed.

It seems to me that 'sub decode' in Encode.pm is doing something wrong.
Unfortunately I do not understand what is going on here. Perhaps the
Marc as maintainer has an idea?

Regards,
Rainer Hurling


sessionInfo()
R Under development (unstable) (2013-08-15 r63591)
Platform: amd64-portbld-freebsd10.0 (64-bit)

locale:
[1] C/de_DE.UTF-8/de_DE.UTF-8/C/de_DE.UTF-8/de_DE.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] WriteXLS_3.2.1

loaded via a namespace (and not attached):
[1] tools_3.1.0


> 
> Hugo Varet
> 
> 
> 
> 2013/8/17 Rainer Hurling <rhurlin at gwdg.de>
> 
>> Am 13.08.2013 19:40, schrieb Hugo Varet:
>>> Dear R users,
>>>
>>> I've just updated the WriteXLS package (on R 3.0.1) and I now have an
>> error
>>> when exporting a data.frame with the argument Encoding="latin1". For
>>> example, these two lines work:
>>>    library(WriteXLS)
>>>    WriteXLS("iris", "iris.xls")
>>> whereas these ones don't work:
>>>   library(WriteXLS)
>>>   WriteXLS("iris", "irislatin1.xls",Encoding="latin1")
>>> I get this message:
>>> Argument "Sepal.Length" isn't numeric in subroutine entry at
>>> C:/Perl64/lib/Encode.pm line 217, <CSVFILE> line 1.
>>> Modification of a read-only value attempted at C:/Perl64/lib/Encode.pm
>> line
>>> 218, <CSVFILE> line 1.
>>> The Perl script 'WriteXLS.pl' failed to run successfully.
>>> Message d'avis :
>>> l'exécution de la commande 'perl
>>> -I"C:/Users/varet/Documents/R/win-library/3.0/WriteXLS/Perl"
>>> "C:/Users/varet/Documents/R/win-library/3.0/WriteXLS/Perl/WriteXLS.pl"
>>> --CSVPath "C:\Users\varet\AppData\Local\Temp\RtmpEzqFNz/WriteXLS"
>> --verbose
>>> FALSE --AdjWidth FALSE --AutoFilter FALSE --BoldHeaderRow FALSE
>> --FreezeRow
>>> 0 --FreezeCol 0 --Encoding latin1
>> "C:\Users\varet\Desktop\irislatin1.xls"'
>>> renvoie un statut 255
>>>
>>> Does anyone know why it failed? May it be a problem with Perl?
>>>
>>> Thanks for your help,
>>>
>>> Hugo Varet
>>
>> Does this also occur with WriteXLS version 3.2.1 ?



More information about the R-help mailing list