• R语言
  • LyX和Knitr综合使用问题

各位大侠好:

我用LyX写好了一段文档导出代码如下:

%% LyX 2.0.4 created this file. For more info, see http://www.lyx.org/.

%% Do not edit unless you really know what you are doing.

\documentclass[a4paper]{ctexart}

\usepackage{CJK}

\pagestyle{headings}

\usepackage[active]{srcltx}

\makeatletter

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% LyX specific LaTeX commands.

\special{papersize=\the\paperwidth,\the\paperheight}

\makeatother

\usepackage{ctex}

\begin{document}

\begin{CJK}{GBK}{}%

\title{报告}

\maketitle

\section{Introduction}

\section{Materials and Methods}

\section{Results and Discussion}

\section{Conclusion}

<<plot>>=

plot(1:100)

@

\end{CJK}

\end{document}

在R里执行的时候报如下的错:

> knit2pdf("testLyx.Rnw")

processing file: testLyx.Rnw

|>>>>>>>>>>>>>>>>>>>>>> | 33%

ordinary text without R code

|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> | 67%

label: plot

|>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>| 100%

ordinary text without R code

output file: E:\work\testLyx.tex

错误: running 'texi2dvi' on 'testLyx.tex' failed

LaTeX errors:

! LaTeX Error: File `srcltx.sty' not found.

Type X to quit or <RETURN> to proceed,

or enter new name. (Default extension: sty)

此外: 警告信息:

运行命令'"d:\CTEX\MiKTeX\miktex\bin\texi2dvi.exe" --quiet --pdf "testLyx.tex" -I "d:/PROGRA~1/R/R-215~1.0/share/texmf/tex/latex" -I "d:/PROGRA~1/R/R-215~1.0/share/texmf/bibtex/bst"'的状态是1

请问是怎么回事?

我在LyX里生成pdf的时候也是报错,无法成功,请高手指教。

谢谢!

1 年 后

同情你 没人回复.

我也遇到跟你一样的问题.在Rsutdio中运行

knit2pdf("testLyx.Rnw") 
失败

也不是全失败 至少tex中间文件还是正确生成了.</p>

于是手动去运行..MikTex 的bin目录texi2dvi.exe

texi2dvi knitr-minimal.tex --pdf


结果就能成功生成pdf

如下:

Output written on knitr-minimal.pdf (1 page, 57301 bytes).

Transcript written on knitr-minimal.log.</p>

最后 我回到原生的Rgui中运行 啥问题也没发生 一切正常

<br />
>knit2pdf("knitr-minimal.Rnw")</p>
<p>|<br />
|.................................................................| 100%<br />
ordinary text without R code</p>
<p>output file: knitr-minimal.tex</p>
<p>[1] "knitr-minimal.pdf"<br />
</p>

初步结论: 是Rstudio的问题.别太放心上了

最后赞一句 谢老大的knitr包真是个天才的设计.

中文文档一直存在编码问题,不过几个月前基本都解决了,现在RStudio和LyX都能正确处理编码了。

谢老大 早上好.

一针见血的指明问题了

的确是中文的问题,我也正在查阅资料琢磨解决.

我是这几天才刚用上knitr 并且之前的tex基础几乎为0,在cos上看见别人类似的问题,还没仔细分析就胡球回答一通 惭愧了.

BTW,我主要是在使用 blotter+quantmod+quantstrat等几个包

主要目的是想用您的knitr包帮助动态生成 证券交易的策略验证报告.

两个月前正式接触R.不过呢我有两年的Python编程经验.

这方面 请谢老大 以后多指点.[s:13]

嗯,很高兴你能用上我的东西。

回复 第5楼 的 谢益辉:亲,《Dynamic Documents with R and knitr》 这本书啥时候有中文版?谢谢

亲,目前我只能回复一个字:等

6 个月 后

回复 第7楼 的 谢益辉:[s:12]老大啊!!knitr 支持中文到底到什么程度啊[s:15]

到底为什么,求指点。

R,RStudio,lyx都是最新版了

按照你这上面http://www.screenr.com/SvL8的说明,一切都是河蟹的,但是用plot画图怎么就不可以 啊

老是报错,警告。

如这个chunk:

<<example_cn,echo=TRUE,fig=TRUE>>=<br />
x <- rnorm(100)<br />
y <- rnorm(100)<br />
plot(x, y, main="chinese中文")<br />
@
</p>