Thanks again. Putting options(encoding="") into the R code chunk before calling the read.xls function indeed did the trick. Now, I have one last question: How can I edit the LyX preference file to call R with options(encoding='UTF-8'). I prefer to edit the LyX preference file rather than the Sweave.sh file, because I want to run R with UTF-8 only when I use XeTeX. By editing the LyX preference file, I assume it would be possible to define different R encoding setups for different converters.

Erich


On Wed, 12 May 2010 14:43:52 -0400
 Duncan Murdoch <murdoch.dun...@gmail.com> wrote:
On 12/05/2010 2:29 PM, Erich Studerus wrote:
Thank you! I edited the Sweave.sh file and it works now for reading data stored as R data files, but the read.xls function from the gdata-package does no longer work.

options('encoding'='UTF-8')
require(gdata)
read.xls("http://www.schwerhoerigkeit.pop.ch/hoergeraete_test.xls";, stringsAsFactors = F)[2,2]

This gives NA as output and a warning that there was an invalid entry for the connection. Is there a way to use read.xls with UTF-8 encoding?

I don't know, you'd have to ask its authors. But you can probably set options(encoding="") before calling it. (I'm assuming the read.xls() is in a code chunk in your Sweave file. I would guess that you don't need to set the encoding back to UTF-8 afterwards, but you might: it all depends on when Sweave() opens its
output file.)

Duncan Murdoch




On Wed, 12 May 2010 12:45:51 -0400
  Duncan Murdoch <murdoch.dun...@gmail.com> wrote:
> On 12/05/2010 11:36 AM, Erich Studerus wrote:
>> Putting \usepackage[cp1252]{inputenc} into my preamble is not an option, >> because XeTeX unlike LaTeX needs UTF-8 has input encoding. My goal is also
>> to have a LyX document that can be compiled both on Mac and Windows.
>>
>> I usually compile my Lyx-Sweave documents by one click of a button from
>> within Lyx. R code chunks are therefore executed by calling R from the
>> command line. If anybody knows how to run R with options(encoding="UTF-8")
>> from the command line under windows, that would be helpful.
>>
>> The command that calls R during compilation is contained in this file:
>> http://cran.r-project.org/contrib/extra/lyx/preferences
>> > > > You can do it with a little work. If you look at the rhome/bin/Sweave.sh >file, you'll see that > > R CMD Sweave file.Rnw > > just executes something like > > echo "library(\"utils\"); Sweave(\"file.Rnw\")" | R --no-restore --slave > > What you want is to execute > > echo "library(\"utils\"); options(encoding="UTF-8"); Sweave(\"file.Rnw\")" >| R --no-restore --slave > > You could edit the rhome/bin/Sweave.sh file appropriately if you always >want Sweave to use UTF-8, or you could edit your Lyx preference file to put >in a line like this instead of what it had. > > Duncan Murdoch

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to