【发布时间】:2017-11-08 09:31:08
【问题描述】:
我在 Linux mint 和 Windows 7 上都安装了 Sweave 和 knitr 包,它在 Windows 上运行良好,但在使用 rstudio 时失败在 Linux 中。安装完pkgs后,我写了一个简单的dw.Rnw如下:
\documentclass{article}
\begin{document}
The regression model is as follows
<<echo=TRUE>>=
pop=read.table("pop.txt",header=TRUE)
attach(pop)
lm.sol=lm(y~year)
summary(lm.sol)
@
\end{document}
当我在 rstudio 中按下按钮“编译 PDF”时,它会返回以下错误消息:
During startup - Warning messages:
1: Setting LC_CTYPE failed, using "C"
2: Setting LC_COLLATE failed, using "C"
3: Setting LC_TIME failed, using "C"
4: Setting LC_MESSAGES failed, using "C"
5: Setting LC_PAPER failed, using "C"
6: Setting LC_PAPER failed, using "C"
7: Setting LC_MEASUREMENT failed, using "C"
> grDevices::pdf.options(useDingbats = FALSE); require(knitr); knit('dw.Rnw', encoding='UTF-8')
Loading required package: knitr
Warning in readLines(if (is.character(input2)) { :
cannot open file 'dw.Rnw': No such file or directory
Error in readLines(if (is.character(input2)) { :
cannot open the connection
Calls: knit -> readLines
Execution halted
knit 函数似乎有问题。但是,如果我输入
knit("dw.Rnw")
在rstudio的控制台中,成功生成dw.tex文件,我可以用pdflatex编译,最后生成dw.pdf。
那么我的 knitr 或 rstudio 出了什么问题?
【问题讨论】:
-
从启动警告消息看,您设置了一些错误的环境变量,或者在
~/.Rprofile中搞砸了一些东西。请发帖x=as.list(Sys.getenv());str(x[grep('^L[AC]',names(x))])并检查~/.Rprofile是否有问题(如果存在)。 -
非常感谢亿辉!看来我的~/.Rprofile有问题,因为在清除了里面的所有设置后,我可以用rstudio编译pdf了!实际上我在 .Rprofile 中只有以下两个设置: setwd("~/Rproject") options(editor="/usr/bin/vim") 你能告诉我我的设置有什么问题吗?再次感谢。
-
我认为 .Rprofile 中的
setwd()是一种不好的做法,但我看不出它会如何影响您的 R 语言环境。 -
你是对的。我通过在Windows上的
.Rprofile.site中添加setwd()进行测试,然后出现了同样的问题。总之,谢谢亿辉! -
好的,我已经写了这个作为答案。