cannot install package learnr

Hi everyone. I am having an issue with installing package learnr and I really need help:( I am currently using a MacBook with R version 4.0.2, Rstudio 1.3.959.

Ive used the following codes but they equally say that I can't install the package.

  1. I've updated all the packages by using update.packages()
  2. I used codes like: install.packages("learnr") / install.packages("learnr",dependencies = TRUE, repos=NULL)
  3. It also seemed like the package knitr was the main issue because the error returned "there is no package called knitr" so I used the following codes to install package knitr (which also didn't work): install.packages('knitr', dependencies = TRUE) / install.packages("xfun")
  4. for all questions that ask "Do you want to install from sources the package which needs compilation? (Yes/no/cancel)", I said Yes

An example of the error is the following)

install.packages("learnr")
also installing the dependencies ‘xfun’, ‘knitr’

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

Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) :
there is no package called ‘knitr’
Do you want to install from sources the package which needs compilation? (Yes/no/cancel) Yes
trying URL 'https://cran.rstudio.com/bin/macosx/contrib/4.0/learnr_0.10.1.tgz'
Content type 'application/x-gzip' length 1651477 bytes (1.6 MB)

downloaded 1.6 MB

The downloaded binary packages are in
/var/folders/8_/lnj7j3sx03d1mljsvz65mnbw0000gn/T//RtmpoiLuCh/downloaded_packages
installing the source packages ‘xfun’, ‘knitr’
.
.
.

  • installing source package ‘xfun’ ...
    ** package ‘xfun’ successfully unpacked and MD5 sums checked
    ** using staged installation
    ** libs
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
    ERROR: compilation failed for package ‘xfun’
  • removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/xfun’
  • restoring previous ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/xfun’
    Warning in install.packages :
    installation of package ‘xfun’ had non-zero exit status
  • installing source package ‘knitr’ ...
    ** package ‘knitr’ successfully unpacked and MD5 sums checked
    ** using staged installation
    ** 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.14 is being loaded, but >= 0.15 is required
    Calls: ... namespaceImportFrom -> asNamespace -> loadNamespace
    Execution halted
    ERROR: lazy loading failed for package ‘knitr’
  • removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/knitr’
    Warning in install.packages :
    installation of package ‘knitr’ had non-zero exit status

The downloaded source packages are in
‘/private/var/folders/8_/lnj7j3sx03d1mljsvz65mnbw0000gn/T/RtmpoiLuCh/downloaded_packages’

library(learnr)
Error: package or namespace load failed for ‘learnr’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
there is no package called ‘knitr’

you're on a Mac, so you would have to set it up for compilation, which (I'm not a mac user but I've been told can be tricky)
Perhaps try again but prefer whatever binaries you can get to source, to spare you that trouble ?

The easiest solution would be to answer "no" to this question, you would get a precompiled binary version that is a little older but much easier to install.
If you need to install the latest version from source, then you need to install Xcode in your system (not in R) and the recommended development tools for macOS systems.
https://cran.r-project.org/bin/macosx/tools/

Here is I solved this.

Went to the CRAN site for xfun and downloaded version .14 in the Mac binary "r-release:" area. Installed it in RStudio by selecting package archive file option.

Then went to the CRAN site for knitr and downloaded the 1.28 version in the Mac binary "r-release:" area. Installed as above and I was able to install RMarkdown and create files. learnr installed as well.

1 Like

Try setting type to 'binary'

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

Hi, I've tried to compile the file and tried to solve this but somehow it keeps saying there is no package called knitr

install.packages("~/Desktop/R tutorial/r packages/knitr_1.29.tar.gz", repos = NULL, type = "source")

  • installing source package ‘knitr’ ...
    ** package ‘knitr’ successfully unpacked and MD5 sums checked
    ** using staged installation
    ** 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.14 is being loaded, but >= 0.15 is required
    Calls: ... namespaceImportFrom -> asNamespace -> loadNamespace
    Execution halted
    ERROR: lazy loading failed for package ‘knitr’
  • removing ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library/knitr’
    Warning in install.packages :
    installation of package ‘/Users/joyyun/Desktop/ACTL2102/R tutorial/r packages/knitr_1.29.tar.gz’ had non-zero exit status
    Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) :
    there is no package called ‘knitr’

you need something called xfun

ive tried it but I keep getting the same error

install.packages("~/Downloads/xfun_0.14.tar", repos = NULL)
Error in install.packages : type == "both" cannot be used with 'repos = NULL'
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) :
there is no package called ‘knitr’

Thank you , I had the same problems today and your solution worked great for me!
Macosx Mojave R vs. 4.0.2

1 Like