run install.packages("knitr")

RStudio IDE crashed with unknown reason. After uninstall/install RStudio with R version 3.5.3 and RStudio 1.3.1073 under window 10, run above statement. The installation stopped in somewhere with following lines displayed in the console. I am new to the system and really need help !

install.packages("knitr")
WARNING: Rtools is required to build R packages but is not currently installed. Please download and install the appropriate version of Rtools before proceeding:

https://cran.rstudio.com/bin/windows/Rtools/
Installing package into ‘C:/Users/lin/OneDrive - The someone/Documents 1/R/win-library/3.5’
(as ‘lib’ is unspecified)
also installing the dependency ‘xfun’

There are binary versions available but the source versions are later:
binary source needs_compilation
xfun 0.13 0.16 TRUE
knitr 1.28 1.29 FALSE

Binaries will be installed
trying URL 'https://cloud.r-project.org/bin/windows/contrib/3.5/xfun_0.13.zip'
Content type 'application/zip' length 184719 bytes (180 KB)
downloaded 180 KB

package ‘xfun’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Users\lin\AppData\Local\Temp\RtmpuMr6eE\downloaded_packages
installing the source package ‘knitr’

trying URL 'https://cloud.r-project.org/src/contrib/knitr_1.29.tar.gz'
Content type 'application/x-gzip' length 885623 bytes (864 KB)
downloaded 864 KB

  • installing source package 'knitr' ...
    ** package 'knitr' successfully unpacked and MD5 sums checked
    ** R
    ** demo
    ** inst
    ** byte-compile and prepare package for lazy loading
    Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) :
    namespace 'xfun' 0.13 is being loaded, but >= 0.15 is required
    ERROR: lazy loading failed for package 'knitr'
  • removing 'C:/Users/lin/OneDrive - The Joint Commission/Documents 1/R/win-library/3.5/knitr'
    In R CMD INSTALL
    Warning in install.packages :
    installation of package ‘knitr’ had non-zero exit status

The downloaded source packages are in
‘C:\Users\lin\AppData\Local\Temp\RtmpuMr6eE\downloaded_packages’

You are being asked to update xfun but there is no binaries available for old R versions (like the one you are using) so you need to compile from source, for that you need to have a compiler installed in your system, that is why you are also being asked to install Rtools. You can download it from here
https://cran.r-project.org/bin/windows/Rtools/history.html

I would recommend (for almost everyone) updating R before installing Rtools and getting into the business of building source packages. The only time I wouldn't is if they had an older Mac which can't be updated to a more recent version of OSX and for which there's not a readily available newer R version.

It just saves so much time and energy, for everyone, in the long run.

Thank you so much! I am new to R and RStudio. Since I’ve tried many steps before I got your response, I want to install R and RStudio from beginning.

Please let me know if my actions are correct

  1. Uninstall/install the most current R from : https://cran.r-project.org/bin/windows/base/
  2. Uninstall/install the most current RStudio from: Download RStudio - RStudio
  3. Download and install Rtools from https://cran.r-project.org/bin/windows/Rtools/history.html
  4. Install all needed packages including knit

Based on my previous experience, I have 3 questions

  1. Should R and RStudio files be in the same folder?
  2. When installing RStudio, the files go to C:/Program Files/R. But when installing packages, the packages go to another folder like C:/Users/lin/OneDrive - The Company/Documents 1/R/win-library/3.5/knitr. Why is this? Should the packages be in the same folder as C:/Program Files/R or can I select to put into same folder or it doesn't matter at all?
  3. For generating pdf report, I need to Install MiKTex and run tinytex::install_tinytex(). After install R and RStudio, do I need to re-install MiKTex and re-run tinytex?

The latest R version is 4.0.2 but it seems you are using a very old one instead (3.5).

There are two library folders by default, the system level package library located at the installation folder and a user level package library at the user's home folder. You can change the defaul folder by setting your R_LIBS_SITE environmental variable on a .Reviron or .Rprofile file

# In .Renviron file you can set it by adding this line
R_LIBS_SITE="C:\\Program Files\\R\\R-4.0.2\\library"

Actually you only need one of these either MiKTex or tinytex and you don't need to reinstall them.

1 Like

And, unless you are doing LaTeX work outside of R/R Studio/R Markdown or you either need to use things coming from obscure \LaTeX packages, I would recommend you choose tinytex over MiKTex. Updates and bug fixes particular to \LaTeX in R/R Markdown will be handled as updates to the package and it will be one fewer thing for you to need to maintain on your own.

That said, knitr isn't always the best at passing along useful error messages from \LaTeX so I often find it invaluable to use the keep_tex: true option in my YAML header,

---
title: "My Title"
output:
  pdf_document:
    keep_tex: true
---

which instructs knitr to not delete the intermediary .tex file it creates. I (or you now) can then open the .tex file in your \LaTeX IDE of choice. On Windows (and Linux) I quite like TeXstudio. Once there, I just try to compile the pdf without any changes to see the entire list of errors.

But, again, if you're not doing a ton of PDF generation or you're not doing anything exotic, tinytex is almost certainly enough. So, I'd start there and only move to a full blown \LaTeX installation when you grow into it naturally.

Thank you so much. Following your instruction, the problem is solved after re-install R. I really want to keep all user level packages in my preferred folder, but couldn't find .Reviron nor .Rprofile file. Under C:\Program Files\RStudio, there are bin, R, resources, www sub-folders, where is it located? or sub-folder under C:\Program Files\R\R-4.0.2?

Thanks again!

I used to install Latex, but without it, MikTex and tinytex work fine for my pdf report generation. Thank you very much for the explanation about Latex.

This article explains how to use startup files in R

pandoc document conversion failed with error 1

Unknow reason, RStudio crashed. Knitting markdown code and got error after reinstalling R /RStudio.

These are messages:

output file: irf_master.knit.md

"C:/Program Files/RStudio/bin/pandoc/pandoc" +RTS -K512m -RTS irf_master.utf8.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output irf_master.tex --self-contained --highlight-style tango --pdf-engine pdflatex --variable graphics --lua-filter "C:/Users/lin/OneDrive - The /Documents 1/R/win-library/4.0/rmarkdown/rmd/lua/pagebreak.lua" --lua-filter "C:/Users/lin/OneDrive - The /Documents 1/R/win-library/4.0/rmarkdown/rmd/lua/latex-div.lua" --include-in-header "C:\Users\lin\AppData\Local\Temp\Rtmp0eLx7Y\rmarkdown-str1f816d01bca.html" --variable "geometry:margin=1in" --include-in-header "C:\Users\lin\AppData\Local\Temp\Rtmp0eLx7Y\rmarkdown-str1f89387e0.html"

pandoc.exe: irf_master.utf8.md: openBinaryFile: does not exist (No such file or directory)

Error: pandoc document conversion failed with error 1

In addition: There were 13 warnings (use warnings() to see them)

Execution halted

This is a different issue, please open a new topic for it, providing a relevant reproducible example.

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.