I am a new user to RStudio, and have encountered an error when using a .rmd file and Knit HTML
If I have an install.packages line:
install.packages('ggplot2');
library(ggplot2);
when I click Knit HTML, an error is returned:
Error in contrib.url(repos, "source") : trying to use CRAN without setting a mirror calls: ... withVisible -> eval -> eval -> install.packages -> contrib.url Execution halted
I was able to work around this using:
if (!require('ggplot2'))
{
install.packages('ggplot2');
library(ggplot2);
}
If I'm writing a .rmd, do I need to use the if (!require(
line every time I install a new package? Is there a way to avoid this so I can write install.packages(
only?
I was also getting same error while using the Knit document and I did below things in the R script :
Run the command in console to set your default repository : options(repos=structure(c(CRAN="http://cran.r-project.org")))
Add the below code in your R studio : options(repos="https://cran.rstudio.com" )
Add the url reference for packages needed, for example : install.packages("pscl", repos = "https://cran.rstudio.com")