10

我在 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}

当我在 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 有什么问题?

4

1 回答 1

12

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

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

于 2013-06-03T18:45:20.953 回答