Error R Studio Knit HTML with install.packages line

I was also getting same error while using the Knit document and I did below things in the R script :

  1. Run the command in console to set your default repository :
    options(repos=structure(c(CRAN=”http://cran.r-project.org”)))

  2. Add the below code in your R studio :
    options(repos=”https://cran.rstudio.com” )

  3. Add the url reference for packages needed, for example :
    install.packages(“pscl”, repos = “cran.rstudio.com“)

You don’t need install.package() line everytime.

Normally you should install packages in console or a separate interactive session or delete that line after installation of that library (here it’s ggplot).

Just use library(ggplot2)

Hope it helps

Read more here: Source link