3

この質問は、tex.sx に関する次の質問から生じました: Sweave generated invalid LaTeX . 問題は、ロケールが UTF-8 に設定され、ファイルが UTF-8 として保存されてSweaveいるにもかかわらず、ファイルのエンコーディングを認識していないようです。.Rnw最終的に、.RnwASCII 以外の文字を含むファイルは、結果のファイルに NA を生成することになり.texます。その質問へのコメントを読むことができるように、別のユーザーは明らかに同一の設定で問題を示していません。(Mac では R 2.13.1) 失敗する最小限のドキュメントを次に示します。

アップデート

Aaron の提案に基づいてsessionInfo、ファイルに追加した.Rnwところ、実際の問題が明らかになりました。ファイルを処理するSweaveと、ロケールが変わるようです。

.Rnwファイル

\documentclass{article}
\usepackage[utf8]{inputenc}
\begin{document}
Some non-ascii text: éüáî
<<>>=
sessionInfo()
@ 
\end{document}

これをSweaveで実行すると、次の.texファイルが生成されます。非 ASCII 文字を含む行は、によって変換されましNASweave。また、ロケールが変更されたようです。

結果.texファイル

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{Sweave}
\begin{document}
NA
\begin{Schunk}
\begin{Sinput}
> sessionInfo()
\end{Sinput}
\begin{Soutput}
R version 2.13.1 (2011-07-08)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] C

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

loaded via a namespace (and not attached):
[1] tools_2.13.1
\end{Soutput}
\end{Schunk}
\end{document}

sessionInfo()R.appリターン内から:

> sessionInfo()
R version 2.13.1 (2011-07-08)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

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

更新 (アーロンへの返信)

> text <- readLines("sweave-enc-test.Rnw", warn = FALSE)
> enc <- tools:::.getVignetteEncoding(text, convert = TRUE)
> 
> text
[1] "\\documentclass{article}"     "\\usepackage[utf8]{inputenc}" "\\begin{document}"           
[4] "Some non-ascii text: éüáî"    "\\end{document}"             
> enc
[1] "UTF-8"
> iconv(text, enc, "")
[1] "\\documentclass{article}"     "\\usepackage[utf8]{inputenc}" "\\begin{document}"           
[4] "Some non-ascii text: éüáî"    "\\end{document}"      

(これは、R コンソール内からの出力R.appです。)

4

1 に答える 1