knit to word is´t working

HI guys,

im trying to knit my codes in a word document for my uni. But i always get the error: "tryinig to use CRAN without setting a mirror"

i goes something like:

install.packages("stringr")
etc...

Ive read that install.packages can be the issue, but i want it in the document, just to be safe.

Can you guys help me out?
Thanks!

You shouldn't include install commands on a Rmd file, if you want to keep it there as a reference, comment the command with # so it doesn't get executed.

#install.packages("stringr")

As another option you can also put the code in a chunk with eval = FALSE if you still want to be able to execute it interactively and be shown highlighted in the output but not run it during compilation.

Rendering a Rmarkdown should indeed not installed package - that is not recommended.

Regarding this specific error, this is because install.packages() is run non interactively and no default repos is defined in R options. Setting that would solve it, but again not recommended.

Hi, thanks i put "#" in front of install.packages, but now i get an other error saying "error in eval (expr, envir, enclos): object 'economic_data' not found ....". The thing is everything works fine when i plot everything in the other r file, so i don´t understand what the problem is.

Have in mind that when you knit an Rmd document the code gets executed in a clean environment other than the one you are currently working on so you have to include the necessary code to load any external data you are working with.

For example, if economic_data comes from a csv file, you would include something like this

economic_data <- read.csv("path_to_your _file.csv")

If you need more specific help, please provide a proper REPRoducible EXample (reprex) illustrating your issue.

1 Like

Hi, i just copied the entire code i used in the other file, thats why i am so confused. So i´ve read the dataset just like you mentioned.

As I said, we need a REPRoducible EXample (reprex) illustrating your issue to be able to help you any further.

1 Like

@ThaBrazilianGuy , the answer given by @andresrcs is the correct one. This means that the object is not found - so it means either it is not created inside the Rmd document, or either the object is in a package you have forgot to load using library() or data(..., package = ...)

Please check you Rmd document that you did not provide to be sure that all your R object are within the document. All the R code must be able to run without external object.

Thanks

okey so i solved this issue somehow, but now when i want to knit my document to word i get the following error:
namespace 'rlang' 0.4.12 is already loaded, but >= 1.0.1 is required

i tried to update it with:
install.packages("https://cran.r-project.org/src/contrib/Archive/rlang/rlang_1.0.1.tar.gz", repos = NULL, type="source")

i also updated R and Rstudio just to be sure but i still get this error.

its very frustrating..

sry full error is:
Error: package or namespace load failed for ‘mosaic’ in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]):
Namensraum ‘rlang’ 0.4.12 ist bereits geladen, aber >= 1.0.1 wird gefordert

If you keep getting the same error message then the update process has been unsuccessful, to help you with that we need to see the complete console output you get when you try to install it.

Also, why are you trying to install it from a downloaded source file?, that is very prone to failure since you might be lacking other package dependencies or the required compiling tools. If you don't have a very compelling reason to do it that way I would strongly recommend using a normal on-line installation.

install.packages("rlang")
1 Like

And if you still have installation problem, you could try running installation with pak

Basically what I would recommand is to be sure to close any open R (or RStudio) session, then open a new empty project RStudio (or better just R console) and then run the installation of rlang.

This topic was automatically closed 21 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.