Unable to install rmarkdown package

142 views Asked by At

When trying to create a quarto document, a message appears stating that rmarkdown is not installed, when I attempt to install it several different ways, the same error is returned.

I updated RStudio, installed RTools4.3 and 4.0, none of which worked. I then tried to install packages individually, this also did not work for bslib. Each time the same error is returned.

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/x/OneDrive/Documents/R/win-library/4.1’
(as ‘lib’ is unspecified)
also installing the dependencies ‘htmltools’, ‘bslib’


  There are binary versions available but the source versions are
  later:
          binary source needs_compilation
htmltools  0.5.5  0.5.7              TRUE
bslib      0.4.2  0.6.1             FALSE
rmarkdown   2.21   2.25             FALSE

  Binaries will be installed
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.1/htmltools_0.5.5.zip'
Content type 'application/zip' length 361526 bytes (353 KB)
downloaded 353 KB

package ‘htmltools’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
    C:\Users\x\AppData\Local\Temp\RtmpsTqDaS\downloaded_packages
installing the source packages ‘bslib’, ‘rmarkdown’

trying URL 'https://cran.rstudio.com/src/contrib/bslib_0.6.1.tar.gz'
Content type 'application/x-gzip' length 6059587 bytes (5.8 MB)
downloaded 5.8 MB

trying URL 'https://cran.rstudio.com/src/contrib/rmarkdown_2.25.tar.gz'
Content type 'application/x-gzip' length 2188934 bytes (2.1 MB)
downloaded 2.1 MB

* installing *source* package 'bslib' ...
** package 'bslib' successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : 
  namespace 'htmltools' 0.5.5 is being loaded, but >= 0.5.7 is required
Calls: <Anonymous> ... withCallingHandlers -> loadNamespace -> namespaceImport -> loadNamespace
Execution halted
ERROR: lazy loading failed for package 'bslib'
* removing 'C:/Users/x/OneDrive/Documents/R/win-library/4.1/bslib'
Warning in install.packages :
  installation of package ‘bslib’ had non-zero exit status
ERROR: dependency 'bslib' is not available for package 'rmarkdown'
* removing 'C:/Users/x/OneDrive/Documents/R/win-library/4.1/rmarkdown'
Warning in install.packages :
  installation of package ‘rmarkdown’ had non-zero exit status

The downloaded source packages are in
    ‘C:\Users\x\AppData\Local\Temp\RtmpsTqDaS\downloaded_packages’
1

There are 1 answers

0
r2evans On

Let's disect the errors, warnings, and messages.

Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : 
  namespace 'htmltools' 0.5.5 is being loaded, but >= 0.5.7 is required

If we also look at the initial message and your selection of binary:

  There are binary versions available but the source versions are
  later:
          binary source needs_compilation
htmltools  0.5.5  0.5.7              TRUE
bslib      0.4.2  0.6.1             FALSE
rmarkdown   2.21   2.25             FALSE

  Binaries will be installed

we should not be surprised that 0.5.5 is still being installed.

We need to get past that point, and there are a few options.

  1. Upgrade R.

    You're on R-4.1. While the CRAN page for htmltools clearly says that it has 0.5.7, the "Windows binaries:" section provides links to three versions, and if you mouse over them you'll see in the url-path which versions of R they are supporting:

    • the r-devel version of the package points to https://cran.r-project.org/bin/windows/contrib/4.4/htmltools_0.5.7.zip; the /4.4/ portion means that it is for R-4.4 (not yet released);
    • r-release supports R-4.3;
    • r-oldrel supports R-4.2

    Do not try to install a binary package for a different version of R (while it might work, it might cause a global meltdown or famine in Nebraska or something else not-good).

    All of this means that CRAN is no longer providing windows binary packages for R-4.1 and older. R-4.2 was released almost two years ago, which pushed R-4.1 to the "oldrel" category; and then R-4.3 was released in April 2023, pushing R-4.1 out of binary-support. If you update R to 4.2 or newer (4.3.2 is current), then when you try to install htmltools you will get version 0.5.7.

    Updating R from 4.1 to 4.2 or 4.3 will require that you reinstall all packages. Yes, this is cumbersome and inconvenient and will definitely take time. There are many ways to automate this step (including some pre-update prep), one article discussing this is https://universeofdatascience.com/how-to-reinstall-all-packages-after-updating-r/.

  2. Use Posit's Package Manager, https://packagemanager.posit.co. It supports binary packages for R versions going back to R-4.0, including htmltools_0.5.7, so in a pinch if you follow their directions to update your options(repos=..) correctly, then go to install htmltools again, it should install 0.5.7.

  3. Install Rtools40 (again?). Assuming you choose to not update R, then Rtools version 40 is required for R-4.0 through R-4.1.3. Once you download the .exe file and install it, then you will need to completely exit and restart RStudio (if you're using that IDE) and R.

    (Note that if you chose to upgrade R back in option 1, then you will need a different version of Rtools as well. The rest of the steps for the most part are the same, you will need to verify the actual directory on C: where it was installed.)

    But since you say you've done that, we need to go through more steps. Check Sys.getenv("PATH") and look for C:\rtools\ in the ;-delimited list of directories (in a single string). (It might be easier to visualize if you do strsplit(Sys.getenv("PATH"), ";")[[1]] easier to read. If you don't see it in there but the directory exists, then somehow the installer didn't do what it normally does: update the environment variables in your operating system for the PATH. Let's do it manually:

    1. Press the Start key and type in "Environment Variables". It should open a small window titled "System Properties", click on the "Environment Variables..." button at the bottom.

    2. You should see both "User variables for..." and "System variables". I want you to check (but not update) the "System variables" for a row on Path, double click on that. Verify that you do not see C:\Rtools40 or C:\Rtools (you should check which was installed) in the list of directories. If you do, then make sure it is the correct directory name and stop, do not go on to step 3, you can close the env-var and sys-prop windows.

    3. Look in the "User variables" section, double-click on Path. You should have a new window with a list of directories. If you see an incorrect version of the Rtools directory, fix it to what was actually installed. If you don't see one, click New and type in the full path to the bin directory, likely C:\Rtools40\usr\bin. Close out.

    Once the PATH has been updated, you need to get it recognized. At a minimum, this means restarting the IDE you're using (likely RStudio) completely. On some corporate computers, you may also need to log out and log back in to see the changes. Once you do that, try Sys.which("make"), and if you get the empty string "" then that means something else went wrong and you may need to bring in IT support to look more specifically at your computer.

A related answer is https://stackoverflow.com/a/77240392/3358272, consider reading through that as well (much overlap with this).