Thanks, but that doesn't seem to be the problem but rather a symptom.
First, I've installed 117 packages into that location successfully. I can manually create and delete files there. By monitoring the location during the failed devtools installation, I can see that the 00LOCK-xml2 folder is created then removed from that location.
Second, here is the output when I run R with sudo:
> install.packages("devtools")
Installing package into ‘/usr/local/lib/R/site-library’
(as ‘lib’ is unspecified)
also installing the dependencies ‘xml2’, ‘roxygen2’, ‘rversions’
trying URL 'https://cloud.r-project.org/src/contrib/xml2_1.3.3.tar.gz'
Content type 'application/x-gzip' length 283965 bytes (277 KB)
==================================================
downloaded 277 KB
trying URL 'https://cloud.r-project.org/src/contrib/roxygen2_7.1.2.tar.gz'
Content type 'application/x-gzip' length 267337 bytes (261 KB)
==================================================
downloaded 261 KB
trying URL 'https://cloud.r-project.org/src/contrib/rversions_2.1.1.tar.gz'
Content type 'application/x-gzip' length 42064 bytes (41 KB)
==================================================
downloaded 41 KB
trying URL 'https://cloud.r-project.org/src/contrib/devtools_2.4.3.tar.gz'
Content type 'application/x-gzip' length 372413 bytes (363 KB)
==================================================
downloaded 363 KB
* installing *source* package ‘xml2’ ...
** package ‘xml2’ successfully unpacked and MD5 sums checked
** using staged installation
Found pkg-config cflags and libs!
Using PKG_CFLAGS=-I/usr/include/libxml2
Using PKG_LIBS=-lxml2
** libs
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0 -fvisibility=hidden -fpic -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c connection.cpp -o connection.o
gcc -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0 -fpic -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c init.c -o init.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0 -fvisibility=hidden -fpic -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c xml2_doc.cpp -o xml2_doc.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0 -fvisibility=hidden -fpic -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c xml2_init.cpp -o xml2_init.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0 -fvisibility=hidden -fpic -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c xml2_namespace.cpp -o xml2_namespace.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0 -fvisibility=hidden -fpic -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c xml2_node.cpp -o xml2_node.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0 -fvisibility=hidden -fpic -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c xml2_output.cpp -o xml2_output.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0 -fvisibility=hidden -fpic -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c xml2_schema.cpp -o xml2_schema.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0 -fvisibility=hidden -fpic -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c xml2_url.cpp -o xml2_url.o
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I../inst/include -I/usr/include/libxml2 -DUCHAR_TYPE=wchar_t -DU_SHOW_CPLUSPLUS_API=0 -fvisibility=hidden -fpic -g -O2 -fdebug-prefix-map=/build/r-base-lENDSu/r-base-4.1.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g -c xml2_xpath.cpp -o xml2_xpath.o
g++ -std=gnu++14 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o xml2.so connection.o init.o xml2_doc.o xml2_init.o xml2_namespace.o xml2_node.o xml2_output.o xml2_schema.o xml2_url.o xml2_xpath.o -lxml2 -L/usr/lib/R/lib -lR
installing to /usr/local/lib/R/site-library/00LOCK-xml2/00new/xml2/libs
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded from temporary location
** checking absolute paths in shared objects and dynamic libraries
mv: cannot move '/usr/local/lib/R/site-library/00LOCK-xml2/00new/xml2' to '/usr/local/lib/R/site-library/xml2': Permission denied
ERROR: moving to final location failed
ERROR: dependency ‘xml2’ is not available for package ‘roxygen2’
* removing ‘/usr/local/lib/R/site-library/roxygen2’
ERROR: dependency ‘xml2’ is not available for package ‘rversions’
* removing ‘/usr/local/lib/R/site-library/rversions’
ERROR: dependencies ‘roxygen2’, ‘rversions’ are not available for package ‘devtools’
* removing ‘/usr/local/lib/R/site-library/devtools’
The downloaded source packages are in
‘/tmp/RtmpIhpjrk/downloaded_packages’
Warning messages:
1: In install.packages("devtools") :
installation of package ‘xml2’ had non-zero exit status
2: In install.packages("devtools") :
installation of package ‘roxygen2’ had non-zero exit status
3: In install.packages("devtools") :
installation of package ‘rversions’ had non-zero exit status
4: In install.packages("devtools") :
installation of package ‘devtools’ had non-zero exit status
>
As you can see, there is an analogous error message. Again, I've installed many packages to that site previously, so my sudo user has permissions there. I suspect that the permission error is caused by something that is created in the 00LOCK-xml2 directory, but it is removed so quickly in the process, that I can't see it.