[英]CRAN mirror in Rmarkdown
I am very new to Rmarkdown, and I am having problems with setting up libraries that I will use later in my document. 我对Rmarkdown非常陌生,并且在设置库时遇到问题,我稍后将在文档中使用它。
My .Rmd file: 我的.Rmd文件:
# Rmarkdown for tree
####
####
### load packages
```{r}
library(ctv)
install.views('Phylogenetics')
update.views('Phylogenetics')
library(ape)
library(adegenet)
library(phangorn)
```
The error message that I will get is 我将收到的错误消息是
error in available.views(repos = repos) : trying to use CRAN without setting a mirror Calls:
<Anonymous> ... install.views -> .get_pkgs_from_ctv_or_repos -> available.views
How do I install packages successfully so that my downstream analyses will work? 如何成功安装软件包,以便下游分析能够正常工作?
Thanks! 谢谢!
This solution is a combination of two elements. 该解决方案是两个要素的组合。 The first, do not install packages through code chunks in R Markdown without first checking if they are installed. 首先,不要先检查R Markdown中的代码块是否已安装,再通过代码块安装它们。
You can define your mirror programmatically using @Frank 's answer. 您可以使用@Frank的答案以编程方式定义镜像。
Your setup chunk would look like this (repo and packages are just for illustration, change accordingly): 您的设置块应如下所示(存储库和软件包仅供说明,请相应地更改):
```{r setup, include=FALSE, echo=FALSE}
r <- getOption("repos")
r["CRAN"] <- "http://cran.cnr.berkeley.edu/"
options(repos = r)
if(!require(gridExtra)){
install.packages("gridExtra")
}
if(!require(autocrop)){
devtools::install_github("jhollist/autocrop")
}
library("gridExtra")
library("autocrop")
```
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.