首页 文章

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

提问于
浏览
9

我已经在Linux mint和Windows 7上安装了Sweave和knitr软件包,它在Windows上运行良好, but fails when using rstudio in 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("dw.Rnw")

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

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

1 回答

  • 11

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

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

相关问题