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). 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. 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)?

Scott


[1]
https://www.mail-archive.com/search?l=mid&q=20180504204700.o7swd4rmc4uebuot%40Opti1604

Attachment: encoding_export_issue.lyx
Description: application/lyx

Attachment: signature.asc
Description: PGP signature

Reply via email to