この質問は、tex.sx に関する次の質問から生じました: Sweave generated invalid LaTeX . 問題は、ロケールが UTF-8 に設定され、ファイルが UTF-8 として保存されてSweave
いるにもかかわらず、ファイルのエンコーディングを認識していないようです。.Rnw
最終的に、.Rnw
ASCII 以外の文字を含むファイルは、結果のファイルに 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 文字を含む行は、によって変換されましNA
たSweave
。また、ロケールが変更されたようです。
結果.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
です。)