繁体   English   中英

在Rstudio中使用Knitr编译pdf时出错

[英]Error when compiling pdf using knitr in rstudio

我已经在Linux Mint和Windows 7上安装了软件包Sweave以及knitr ,并且在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有什么问题?

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM