Converting R markdown into HTML file

Hey guys!
After typing the code in R markdown file.
Once the knit option is used to view the file in HTML format, following error appears.

"Error in contrib.url(repos,"Source"): trying to use CRAN without setting a mirror calls ...withVisible-> eval ->eval -> install.packages-> contrib.url"

Thank you in advance.

Hi Karthik!

It sounds like your Rmd file is trying to install a package.
To install a package within a knitted document, you need to state which CRAN mirror repository you want to use.

For example,

install.packages("tidyverse, repos = "")

That being said, it is generally not a good idea to install packages in a Rmd document which you are going to knit multiple times.
Ideally you would install the packages needed once, then use library(package_name) within the Rmd to load each package needed.

One lasting way to set your default CRAN mirror is to create a .Rprofile file,
with the line
options(repos=structure(c(CRAN="YOUR FAVORITE MIRROR")))
Which will load every time you start R.


This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.