This question already has answers here:
install.packages fails in knitr document: "trying to use CRAN without setting a mirror"
(3 answers)
Closed 7 years ago.
Below is the error I am getting:
Quitting from lines 46-48 (lesson3_student.rmd)
Error in contrib.url(repos, "source") :
trying to use CRAN without setting a mirror
Calls: <Anonymous> ... withVisible -> eval -> eval -> install.packages -> contrib.url
In addition: Warning message:
In in_dir(opts_knit$get("root.dir") %n% input_dir(), evaluate::evaluate(code, :
You changed the working directory to /Users/Madiyar/Desktop/Facebook Data (probably via setwd()). It will be restored to /Users/Madiyar/Downloads. See the Note section in ?knitr::knit
Execution halted
Thanks for help
The error seems fairly clear to me; you're "trying to use CRAN without setting a mirror"; the problem is that knitting runs in non-interactive mode. Try putting
options(repos="https://cran.rstudio.com" )
in your code. I would say by the way that in knitted code you should probably not
run install.packages() (as #hrbrmstr says in the commenbts, "[m]ost folks want to manage their own package library")
call setwd() to set your working directory manually
Related
I'm new to RStudio and programming in general. When I click on knit to HTML I get this error message. How can I fix this?
Quitting from lines 231-248 (lesson3_student.rmd)
Error in contrib.url(repos, "source") :
trying to use CRAN without setting a mirror
Calls: <Anonymous> ... withVisible -> eval -> eval -> install.packages -> contrib.url
The error message should be fixed, when you set a mirror as argument of the install.packages function:
install.packages("imputeTS",repos = "https://cloud.r-project.org/")
As mentioned in the comments, you only need to install packages once. So you do not necessarily need to do this in the .Rmd document.
Potential user of your .Rmd document will probably see the library("package") calls at the beginning and install the packages on their own.
If you still want to include the install.packages you can do something like this to load the package and only install if necessary:
if(!require("ridge")) {
install.packages("ridge",repos = "https://cloud.r-project.org/")
}
I am receiving this error when trying to knit my R markdown sheet
Error in contrib.url(repos, "source") : trying to use CRAN without setting a mirror calls: ... withVisible -> eval -> eval -> install.packages -> contrib.url Execution halted
Does anyone have any experience with this?
Without the exact code, it is difficult to assess the problem. However, as #NelsonGon writes, this is usually the error from running an installation (install.packages() inside a chunk.
Instead, the library should be installed beforehand and loaded with library(example) inside a chunk to make it available for the markdown environment.
When using R Markdown, R Studio warned me the following message : "Rendering R Markdown documents requires an updated version of the yaml package". So I installed the latest version of the package yaml (2.2.0). But since then, I cannot knit any document in Rmarkdown (even the template or documents that were working just fine before).
I tried downloading older versions of yaml but I get the same message as at the beginning ("requires an updated version").
When I knit a document, I get the following error :
Error in yaml::yaml.load(..., eval.expr = TRUE) :
unused argument (eval.expr = TRUE)
Calls: <Anonymous> ... parse_yaml_front_matter -> yaml_load -> <Anonymous>
I had the unused argument (eval.expr = TRUE) problem after updating RStudio. Somehow it messed up with the R installation and an .Rmd that worked before, stopped working with that error.
What did the trick for me was removing yaml and installing it again.
> remove.packages("yaml")
> install.packages("yaml")
>
I am a new user to RStudio, and have encountered an error when using a .rmd file and Knit HTML
If I have an install.packages line:
install.packages('ggplot2');
library(ggplot2);
when I click Knit HTML, an error is returned:
Error in contrib.url(repos, "source") : trying to use CRAN without
setting a mirror calls: ... withVisible -> eval -> eval ->
install.packages -> contrib.url Execution halted
I was able to work around this using:
if (!require('ggplot2'))
{
install.packages('ggplot2');
library(ggplot2);
}
If I'm writing a .rmd, do I need to use the if (!require( line every time I install a new package? Is there a way to avoid this so I can write install.packages( only?
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)
library(ggplot2);
Hope it helps
I was also getting same error while using the Knit document and I did below things in the R script :
Run the command in console to set your default repository :
options(repos=structure(c(CRAN="http://cran.r-project.org")))
Add the below code in your R studio :
options(repos="https://cran.rstudio.com" )
Add the url reference for packages needed, for example :
install.packages("pscl", repos = "https://cran.rstudio.com")
LyX 2.1.1 fails to compile knitr-manual.lyx and knitr-graphics.lyx as well (currently installed knitr version 1.6).
The error does not say much (i.e. LyX: Cannot convert file -- see screenshot). Could it be related to file-permission bits? How should I go about it?
Maybe of interest,
Sys.getlocale()
[1] "LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=C;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C"
Update
From the message pane, there is indeed an Error line:
12:28:16.235: Quitting from lines 93-93 (/tmp/lyx_tmpdir.gwIlgToM2017/lyx_tmpbuf1/knitr-graphics.Rnw)
12:28:16.238: Error in loadNamespace(name) : there is no package called 'Cairo'
12:28:16.241: Calls: knit ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
12:28:16.244:
12:28:16.247: Execution halted
No cairo? What does this mean in the contect of knitr and LyX/LaTeX?
R was missing the "Cairo" package. And the "tikzDevice" package as well. Installing those two, via
install.packages("Cairo", dep = TRUE)
install.packages("tikzDevice", dep = TRUE)
resolved the issues. At least, there is no compilation error related to missing packages anymore.