0

I am very new to Rmarkdown, and I am having problems with setting up libraries that I will use later in my document.

My .Rmd file:

# 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!

Nate
  • 1
  • 2
  • 1
    http://stackoverflow.com/questions/8475102/set-default-cran-mirror-permanent-in-r (let us know if that answers your q so we can mark this as a dup) – hrbrmstr Aug 08 '16 at 16:38
  • You can do `options(repos=structure(c("https://cloud.r-project.org", "http://www.stats.ox.ac.uk/pub/RWin" ), .Names = c("CRAN", "CRANextra")))` or similar. I got that by running `install.packages("")` manually, picking a repo from the dropdown, then copying `options()$repos`. – Frank Aug 08 '16 at 16:39

1 Answers1

1

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.

You can define your mirror programmatically using @Frank 's answer.

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")

```
FabianUx
  • 32
  • 5