Ncody
Ncody

Reputation: 53

New to RStudio, issues with knit to HTML

I'm new to RStudio and programming in general. When I click on knit to HTML I get this error message. How can I fix this?

Quitting from lines 231-248 (lesson3_student.rmd) 
Error in contrib.url(repos, "source") : 
  trying to use CRAN without setting a mirror
Calls: <Anonymous> ... withVisible -> eval -> eval -> install.packages -> contrib.url

Upvotes: 0

Views: 210

Answers (1)

Steffen Moritz
Steffen Moritz

Reputation: 7730

The error message should be fixed, when you set a mirror as argument of the install.packages function:

install.packages("imputeTS",repos = "https://cloud.r-project.org/")

As mentioned in the comments, you only need to install packages once. So you do not necessarily need to do this in the .Rmd document.

Potential user of your .Rmd document will probably see the library("package") calls at the beginning and install the packages on their own.

If you still want to include the install.packages you can do something like this to load the package and only install if necessary:

if(!require("ridge"))  {
   install.packages("ridge",repos = "https://cloud.r-project.org/")
}

Upvotes: 1

Related Questions