r - CRAN mirror in Rmarkdown -


i new rmarkdown, , having problems setting libraries use later in document.

my .rmd file:

# rmarkdown tree ####  ####   ### load packages ```{r} library(ctv) install.views('phylogenetics') update.views('phylogenetics') library(ape) library(adegenet) library(phangorn) ``` 

the error message

error in available.views(repos = repos) : trying use cran without setting mirror calls:  <anonymous> ... install.views -> .get_pkgs_from_ctv_or_repos -> available.views 

how install packages downstream analyses work?

thanks!

this solution combination of 2 elements. first, not install packages through code chunks in r markdown without first checking if installed.

you can define mirror programmatically using @frank 's answer.

your setup chunk (repo , packages 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")  ``` 

Comments