Unable to install packages from RMarkdown - r

I'm working on a project in RStudio, and all the code runs well. but when I try to get a report in R Makdown, I constantly recieve this error on a chunk which contains installing needed packages:
```{r installing packages, include=FALSE}
install.packages("tidyverse")
library(tidyverse)
install.packages("lubridate")
library(lubridate)
install.packages("ggplot2")
library(ggplot2)
install.packages("dplyr")
library(dplyr)
```
this is the error message: (line 21-32 means all the mentioned chunk.)
Quitting from lines 21-32 (report.Rmd)
Error in contrib.url(repos, "source") :
trying to use CRAN without setting a mirror
Calls: <Anonymous> ... eval_with_user_handlers -> eval -> eval -> install.packages -> contrib.url
Execution halted
any recommendation??
I got the error on first chunk, but each chunk runs perfectly with no error when I run them separately.

Related

How do i fix this knitting error (loadnamespace) and "Error in contrib.url(repos, "source"))?

I have been trying to knit I first got an error but then fixed it on the same line. However, I know keep on getting alternative errors, one
Error: package or namespace load failed for ‘vctrs’ in loadNamespace and in 'hevaan'.
And if I am not getting that error I am getting this
Error in contrib.url(repos, "source") :
trying to use CRAN without setting a mirror
Calls: <Anonymous> ... eval_with_user_handlers -> eval -> eval -> install.packages -> contrib.url
Execution halted
However, I fixed these issues with install.packages and it went to 80% of my knit but now it will not go passed 5%.

Knitting error and dont know how to fix it

I am trying to knit and I keep getting this error:
Error in contrib.url(repos, "source") :
trying to use CRAN without setting a mirror
Calls: <Anonymous> ... eval_with_user_handlers -> eval -> eval -> install.packages -> contrib.url
In addition: Warning message:
In eng_r(options) :
Failed to tidy R code in chunk 'unnamed-chunk-2'. Reason:
Error : The formatR package is required by the chunk option tidy = TRUE but not installed; tidy = TRUE will be ignored.
Execution halted

Knitting error when converting to pdf on rstudio

I keep getting this error when I try to knit to PDF using R Markdown. It has worked before, and I tried installing the package contrib.url but it says it is not available for my version. Any suggestions?
Error in contrib.url(repos, "source") : trying to use CRAN without setting a mirror calls : <Anonymous> ... with visible -> eval -> eval -> install.packages -> contrib.url Execution halted
The error usually comes when you don't set a mirror in the install.packages command. You probably have a call to install.packages somewhere in your markdown document.
Try the following:
install.packages("aPackage",repos = "http://cran.us.r-project.org")
So just add the repos part. You could of course also just install the package before usage and remove the install.packages line completely from your rmarkdown.

R markdown Knit to HTML : Error in library(dplyr)

I am working on R markdown script (RStudio). Individual code chunk works but when i try to Knit to HTML , it throws error as "Error in library(dplyr) : there is no package called 'dplyr' Calls: ... withCallingHandlers -> withVisible -> eval -> eval -> library"
code
##install library
```{r install pkg,include=FALSE,cache=TRUE}
install.packages("kableExtra",repos = "http://cran.us.r-project.org")
install.packages("dplyr", repos = "http://cran.us.r-project.org")
install.packages("ggplot2", repos = "http://cran.us.r-project.org")
```
```{r setup, include=FALSE}
library(knitr)
library(dplyr)
library(ggplot2)
```
Restart R
You should manually install packages and then knit to HDML. Click Tools > Install Packages and then type in the packages

R file won't knit, saying readxl package doesn't exist

I'm using RStudio, and trying to knit my file to hand in my assignment. I installed the package "readxl" to read in a couple of excel files, and it worked fine in the actual coding of the assignment. But when I go to knit the file, I keep getting the error:
Error in library(readxl) : there is no package called 'readxl'
Calls: <Anonymous> ... withCallingHandlers -> withVisible -> eval -> eval ->
library
Execution halted
This is the code in question:
install.packages("tidyverse",repos = "http://cran.us.r-project.org")
library(tidyverse)
install.packages("readxl",repos = "http://cran.us.r-project.org")
library(readxl)
This has been frustrating me for over an hour and I just can't fix it. I can see the readxl package to the right of the console, in the "packages" tab. Any help will be much appreciated

Resources