Can't update packages in 2023.12.1 build 402

I just updated to 2023.12.1 from 2023.09.? Didn't note the previously installed version, sorry. On trying to build an existing book project, it quickly fails, complaining that:
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) :
namespace 'htmltools' 0.5.3 is already loaded, but >= 0.5.4 is required
Calls: local ... is_bs_theme -> loadNamespace -> namespaceImport -> loadNamespace
Execution halted
Error: bookdown::render_book() failed to render the output format 'bookdown::gitbook'.
Execution halted

On trying to update packages, I get the dialog suggesting I restart R before update, and I click Yes. It then fails the install, and repeats the cycle with the dialog again.

In the installation process, it also complains:

install.packages("htmltools")
Error in install.packages : Updating loaded packages
install.packages("htmltools")
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/wmeyer/AppData/Local/R/win-library/4.2’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.2/htmltools_0.5.7.zip'
Content type 'application/zip' length 357577 bytes (349 KB)
downloaded 349 KB

package ‘htmltools’ successfully unpacked and MD5 sums checked
Warning in install.packages :
cannot remove prior installation of package ‘htmltools’
Warning in install.packages :
problem copying C:\Users\wmeyer\AppData\Local\R\win-library\4.2\00LOCK\htmltools\libs\x64\htmltools.dll to C:\Users\wmeyer\AppData\Local\R\win-library\4.2\htmltools\libs\x64\htmltools.dll: Permission denied
Warning in install.packages :
restored ‘htmltools’

The presence of the path containing 00LOCK is likely a problem. Try uninstalling htmltools. If that (allegedly) succeeds, check to make sure the 00LOCK path no longer exists. If it persists, try deleting it. Once 00LOCK is gone, try installing htmltools again.

Thanks, but in the packages list, htmltools doesn't appear. Is there another way to uninstall it? Also, RTools doesn't appear, but was in another complaint, and I am unable to install it.
UPDATE: Part of the problem appears to be that I need to run RStudio as Administrator.

Are you saying that if (in RStudio) you click on the Packages tab, then click the Install button, then (with the Install from: box set to Repository (CRAN)) type htmltools in the Packages box, it is not listed?

No. I am saying that if you look in the bottom right pane, in the Packages list, it is not present.

Correct -- because that lists installed packages, and you do not (yet) have it installed. So try deleting the directory with 00LOCK in the path and then try installing it.

C:\Users\wmeyer\AppData\Local\R\win-library\4.2\00LOCK\htmltools\libs\x64
Does not exist.
C:\Users\wmeyer\AppData\Local\R\win-library\4.2
Does not contain 00LOCK

OK, the lock file was apparently removed. Do you have RTools installed now? One of the first messages suggested you did not.

I do not find it in the list of installed packages. But when I attempt to build the book, I now get this:
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) :
namespace 'rlang' 1.0.5 is already loaded, but >= 1.0.6 is required
Calls: local ... asNamespace -> loadNamespace -> namespaceImport -> loadNamespace
Execution halted
Error: bookdown::render_book() failed to render the output format 'bookdown::gitbook'.
Execution halted

Exited with status 1.

Attempting to update rlang, I get the dialog to restart the R session, and then this:
Restarting R session...

install.packages("rlang")
Error in install.packages : Updating loaded packages

And the dialog again presents. If I click no this time, I get:

install.packages("rlang")
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/wmeyer/AppData/Local/R/win-library/4.2’
(as ‘lib’ is unspecified)
trying URL 'https://cran.rstudio.com/bin/windows/contrib/4.2/rlang_1.1.3.zip'
Content type 'application/zip' length 1577706 bytes (1.5 MB)
downloaded 1.5 MB

package ‘rlang’ successfully unpacked and MD5 sums checked
Warning in install.packages :
cannot remove prior installation of package ‘rlang’
Warning in install.packages :
problem copying C:\Users\wmeyer\AppData\Local\R\win-library\4.2\00LOCK\rlang\libs\x64\rlang.dll to C:\Users\wmeyer\AppData\Local\R\win-library\4.2\rlang\libs\x64\rlang.dll: Permission denied
Warning in install.packages :
restored ‘rlang’

The downloaded binary packages are in
C:\Users\Public\Documents\Wondershare\CreatorTemp\RtmpOk40QZ\downloaded_packages

I would suggest shutting down RStudio and restarting it (without loading any scripts or documents) before attempting to install or update any packages, to reduce the likelihood that the package you are updating is already active in memory.

Did you install RTools? Note that RTools is not an R library; it's a separate program, which is apparently need to compile the source code for R libraries. (I'm on Linux, where the tool chain for compiling libraries is already installed.) So you don't install it within RStudio; you download the exe file from the site you linked, run it to install RTools, and then try installing/updating R libraries.

OK, decided to uninstall.reinstall R, to get the 4.3 level. Then downloaded and installed RTools. Then ran RStudio as Admin, and again tried to update rlang, which again failed, again complaining that RTools is not installed. Surely there must be steps which will walk me through this. I am ready to uninstall the whole chain and start over. My confidence in RStudio updates has plummeted.
UPDATE: The short answer, the one that actually solves the problem, is this:

  • Run R
  • Update Packages
  • Run RStudio