在rstudio中使用knitr编译pdf时出错

zen*_*ang 9 r sweave rstudio knitr

我已经在Linux mint和Windows 7上安装了Sweaveknitr软件包,它在Windows上运行良好,但在Linux中使用rstudio时却失败了.安装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}
Run Code Online (Sandbox Code Playgroud)

当我按下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
Run Code Online (Sandbox Code Playgroud)

功能编织似乎有问题.但是,如果我输入

knit("dw.Rnw")
Run Code Online (Sandbox Code Playgroud)

在rstudio的控制台中,它成功生成文件dw.tex,我可以用pdflatex编译,最后生成dw.pdf.

那我的knitr或rstudio有什么问题?

Yih*_*Xie 11

虽然我仍然不明白为什么,但从上面的评论来看,问题似乎来自~/.Rprofile(特别是setwd()).清理它可以解决问题.

请注意,您可能有其他启动配置文件..Rprofile只有一种可能性.有关?Startup更多信息,请参阅 例如,如果您使用的是Windows,则可能需要查看C:\Program Files\R\etc\Rprofile.site它是否存在.