在Rstudio中使用Knitr编译pdf时出错 [英] Error when compiling pdf using knitr in rstudio

查看:656
本文介绍了在Rstudio中使用Knitr编译pdf时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Linux Mint和Windows 7上安装了软件包 Sweave knitr ,并且在Windows上运行良好,但是在使用rstudio时失败在Linux中.安装完pkgs之后,我编写了一个简单的 dw.Rnw ,如下所示:

I have installed the packages Sweave as well as knitr on both Linux mint and Windows 7, and it works well on Windows, but fails when using rstudio in Linux. After installing the pkgs, I write a simple dw.Rnw as follows:

\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 "时,它会返回以下错误消息:

When I press the button 'Compile PDF' in rstudio, it returns the following error messages:

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

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

It seems there is something wrong with the function knit. However, if I type

knit("dw.Rnw")

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

in the console of rstudio, then it successfully generates the file dw.tex, which I can compile with pdflatex and finally generate dw.pdf.

那么我的knitr或rstudio怎么了?

So what's wrong with my knitr or rstudio?

推荐答案

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

Although I still do not understand why, but from the comments above, the problem seems to come from ~/.Rprofile (in particular, setwd()). Clearing it up solves the problem.

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

Note you may have other startup profile files. .Rprofile is only one possibility. See ?Startup for more information. For example, if you are on Windows, you may need to take a look at C:\Program Files\R\etc\Rprofile.site if it exists.

这篇关于在Rstudio中使用Knitr编译pdf时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆