Am Samstag, den 05.05.2018, 17:26 -0400 schrieb Scott Kostyshak: > The attached .lyx file contains a knitr chunk. If I export to PDF, > the > PDF is created successfully. However, if I export the .R file and run > > source('encoding_export_issue.R', echo = TRUE) > > I get an error: > > Error in nchar(dep, "c") : invalid multibyte string, element 1 > > The reason for this error, from the R perspective, is detailed by > this > r-help ML post [1]. The problem is that when LyX exports the .Rnw > file > (which in turn is used to make the .R file), the .Rnw file is created > with encoding "iso-8859-1". I think that this encoding is consistent > with the encoding that we set for creating .tex files that we export > (if > they contain e.g. an "á" character, as is contained in the attached > .lyx > file).
It is the default encoding for English. It is different for other languages. And sometimes, the encoding is switched when languages are switched. For chunks, the encoding is always the encoding of the surrounding language. > However, R does not interpret files in the same way as LaTeX > engines do. It seems that LaTeX engines automatically handle .tex > files > of various encodings. No, not automatically. The encoding is marked by the inputenc package and the \inputencoding switches. > R, by default, assumes a certain encoding (which > encoding it assumes depends on the output of Sys.getlocale()). For my > system, it appears that UTF-8 is assumed. > > I know very little about file encodings. Is there an improvement that > we > could make? For example, in the attached .lyx file, would it be > reasonable to save the .Rnw file (which is what is used to create the > .R > file) with the default encoding of the system (which in my case seems > to > be UTF-8)? I am not sure what we can do on an "automatic" level here. You might be able to set up a copier for this task. Manually, you can always set the encoding to utf8 in Document > Settings > Language. Jürgen > > Scott > > > [1] > https://www.mail-archive.com/search?l=mid&q=20180504204700.o7swd4rmc4 > uebuot%40Opti1604
signature.asc
Description: This is a digitally signed message part