trying to use CRAN without setting a mirror

I am getting the following error message:
Error in contrib.url(repos, "source") : trying to use CRAN without setting a mirror Calls: . . . withVisible -> eval -> eval -> install.packages

I don't know what is causing the error, nor do I know how to resolve the error. The error only occurs when I try to knit my code; when I run chunk by chunk, I don't get the error.

I thank you for any help you might be able to offer.
John

To help us help you, could you provide a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

Problem while knitting the markdown file into html. Please help.

Quitting from lines 15-35 (reg_model_project.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