install.packages fails in knitr document: trying to use CRAN without setting a mirror
Knitr produces a R session, without a default cran mirror unless you specifically asked for one. We tend to forget we need to set up CRAN for every R session when we use Rstudio because it takes care of it, but only for interactive use, not for knitr.
You could try specifying a mirror as a install.packages
argument:
install.packages("weatherData",repos = "http://cran.us.r-project.org")
Alternatively, you could set up your default CRAN mirror in your .Rprofile
. See this answer.
That said, it is not a good idea to install packages through a knitr document that you will probably compile several times. You should assume people know how to install a missing package if needed, or at least test whether the package is installed before installing it again
if(!require(weatherData)) install.packages("weatherData",repos = "http://cran.us.r-project.org")
install.packages() enforce no CRAN mirror selection?
install.packages("names", repos = "https://cloud.r-project.org")
You could also set the mirror you want with :
options(repos=structure(c(CRAN="getCRANmirrors()$URL[1]")))
in a .Rprofile
file so your R will automatically use this repos when you will call :
install.packages()
.
Related Topics
Reading Multiple CSV Files from a Folder into a Single Dataframe in R
Bigrams Instead of Single Words in Termdocument Matrix Using R and Rweka
How to Convert Integer into Categorical Data in R
Cartesian Product with Dplyr R
Convert a Date Vector into Julian Day in R
R Assigning Ggplot Objects to List in Loop
Moving Color Key in R Heatmap.2 (Function of Gplots Package)
R Function for Returning All Factors
Case-Insensitive Search of a List in R
Use Ggpairs to Create This Plot
Ggplot2, Axis Not Showing After Using Theme(Axis.Line=Element_Line())
How to Export S3 Method So It Is Available in Namespace
Using Two Scale Colour Gradients on One Ggplot