Can not run Knit in rmarkdown

All, I'm having difficulty kniting my rmarkdown file. Error message is below. I'm using the latest R version, I've loaded MikTex and installed- tinytex::install_tinytex(), but no luck. Any help would be appreciated.

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

This is not an error with Rmarkdown, it is an error with R saying you don't have any CRAN repo configure. If you have a call to install.package or else in your Rmd doc, it could cause the error.

Just configure a cran mirror if you haven't one. Are you using RStudio IDE BTW?

I am using R Studio and I did go back to CRAN and select a mirror location, but the result is the same.

It may be an issue with Internet Access, if it can't reach you're CRAN url.

You check CRAN is setup by checking


Anyway, this is not a rmarkdown, or MikteX, or TinyTeX issue. There is something not right with your environment.

Can you install a package from the console ?

it could also depend on what you are knitting maybe, but you did not share.

Thanks for the response. I ran the getOption function and received an error message- "Error in getOptions("repos") : could not find function "getOptions". I am able to install packages from the console. I'm unable to knit a pdf or html.

Oups my bad, there is no S :frowning:


This is odd. Have you tried from the console and not from Rstudio IDE button ?



I ran the function. It returned "TRUE". I am able to render the markdown file in the console. But still unable to knit to pdf or html. Same error message.

It should also have printed something

Si it works in console, but not through the RStudio button ?
What is the version of RStudio you are using ?

This is the message I get when attempting to download tinytex::install_tinytex()..............

downloaded length 42614784 != reported length 99803989URL '': Timeout of 60 seconds was reachedtrying URL ''
Content type 'application/octet-stream' length 99803989 bytes (95.2 MB)
downloaded 95.2 MB

tlmgr conf auxtrees add "C:/PROGRA~1/R/R-4.0.3/share/texmf"

Your first error was about contrib.url so installed packages, and now you are talking about tinytex.
You said rendering at command line work, so tinytex should not be an issue.


rmarkdown::render("file.Rmd", "pdf_document'")

if you want to check.

The message above seems to have downloading the file correctly.

Anyway, update all the package, start in a fresh session and redo the step.

We need a reproducible example if you want us to help further. It is difficult to say much more. Anything can be the cause in your environment installation or else if we can't reproduce on our side.

When I run getOption("repos") I get the following print out: CRAN

But still getting the following error when knitting- Quitting from lines 12-29 (Assignment1_Casino_Station.Rmd)
Error in contrib.url(repos, "source") :
trying to use CRAN without setting a mirror
Calls: ... withVisible -> eval -> eval -> install.packages -> contrib.url
Execution halted

This mean you have some code in the chunk lines 12-29 that causes this issue.
Are you trying to install package from inside the rmarkdown document ?
That is not good practice but it should not error like that.
What is the code in this chunk ?


If you comment the two lines with install.packages, does it work ?

You shouldn't be trying to install packages every time you render a document.

Annnnd we have lift off! Problem solved. Thank you.

1 Like

If your question's been answered (even by you!), would you mind choosing a solution? It helps other people see which questions still need help, or find solutions if they have similar problems. Here’s how to do it:

Done. Thank you, Team R community.

1 Like

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.