[R] Problems with installing R packages from source and running C++ in R, even on fresh R installation

Christophe Bousquet chr_bou@quet @end|ng |rom protonm@||@com
Tue Aug 29 16:41:40 CEST 2023

Dear all,

I am having issues with R that are giving me headaches since a few weeks. Basically, I cannot:
(i) install packages from source
(ii) run packages relying on C++
I really do not understand how and why this is happening [it was working perfectly fine before and I cannot determine when the problem started for sure], and the solution appears to be extremely difficult to find on the Internet. However, based on the number of StackOverflow questions on these issues, I assume they are affecting many persons.
I already posted some questions related to these issues on StackOverflow [https://stackoverflow.com/questions/76979386/how-to-install-r-packages-from-source-on-fresh-r-installation] and on the RStan forum [https://discourse.mc-stan.org/t/cannot-compile-stan-program-from-r-package-brms/32294/22], but without success.

This is kind of infuriating, because (i) I have no issues on my personal laptop and (ii) the same issues keep coming back on my work laptop, even after a full uninstallation of all R-related components [R, RStudio, Rtools, paths...].

Let's say that I managed to successfully uninstall all R-related components [maybe I miss something at this step?]. Then, I reinstall R4.3.1 [R-4.3.1-win.exe] and directly try to install a package from source. I then get the following warning message (which I actually take as an error message, because the whole command does not work):

```> install.packages("PKI", type = "source")
Installing package into ‘C:/Users/Christophe Bousquet/AppData/Local/R/win-library/4.3’
(as ‘lib’ is unspecified)
--- Please select a CRAN mirror for use in this session ---
trying URL 'https://cloud.r-project.org/src/contrib/PKI_0.1-12.tar.gz'
Content type 'application/x-gzip' length 85544 bytes (83 KB)
downloaded 83 KB

The downloaded source packages are in
‘C:\Users\Christophe Bousquet\AppData\Local\Temp\Rtmpg1wwob\downloaded_packages’
Warning message:
In install.packages("PKI", type = "source") :
installation of package ‘PKI’ had non-zero exit status

I guess this is normal, as at that moment Rtools 4.3 is not installed. So I install Rtools 4.3 [rtools43-5550-5548.exe], but I still get the same error message.

However, Rtools 4.3 seems to be recognized by R:

> library(pkgbuild)
> rtools_path()
[1] "C:\\rtools43/usr/bin"
> has_rtools(debug = TRUE)
Found in Rtools 4.3 installation folder
[1] TRUE
> check_rtools(debug = TRUE)
Found in Rtools 4.3 installation folder
[1] TRUE```

Then, if I try to use a package relying on C++, it fails as well.
For instance:

> library(Rcpp)
> evalCpp("21 + 21")

Error in sourceCpp(code = code, env = env, rebuild = rebuild, cacheDir = cacheDir, :
Error 65535 occurred building shared library.

WARNING: The tools required to build C++ code for R were not found.

Please download and install the appropriate version of Rtools:


I am particularly at loss with the warning, as R seems to find Rtools based on the diagnostic performed by pkgbuild (see above).

However, when I run has_compiler() and check_compiler(), there seems to be some issues:

> has_compiler(debug = TRUE)
Trying to compile a simple C file
Running "C:/PROGRA~1/R/R-43~1.1/bin/x64/Rcmd.exe" SHLIB foo.c
> check_compiler(debug = TRUE)
Trying to compile a simple C file
Running "C:/PROGRA~1/R/R-43~1.1/bin/x64/Rcmd.exe" SHLIB foo.cError: Failed to compile C code

Any help would be greatly appreciated :-)

Here is the output of my sessionInfo():

R version 4.3.1 (2023-06-16 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

[1] LC_COLLATE=English_United Kingdom.utf8 LC_CTYPE=English_United Kingdom.utf8 LC_MONETARY=English_United Kingdom.utf8
[4] LC_NUMERIC=C LC_TIME=English_United Kingdom.utf8

time zone: Europe/Zurich
tzcode source: internal

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:
[1] pkgbuild_1.4.2

loaded via a namespace (and not attached):
[1] processx_3.8.2 compiler_4.3.1 R6_2.5.1 cli_3.6.1 prettyunits_1.1.1 tools_4.3.1 crayon_1.5.2 [8] callr_3.7.3 ps_1.7.5

and the output of Sys.getlocale():

[1] "LC_COLLATE=English_United Kingdom.utf8;LC_CTYPE=English_United Kingdom.utf8;LC_MONETARY=English_United Kingdom.utf8;LC_NUMERIC=C;LC_TIME=English_United Kingdom.utf8"```

Many thanks in advance,
Christophe Bousquet
University of Konstanz

Sent from [ProtonMail](https://protonmail.ch), encrypted email based in Switzerland.
	[[alternative HTML version deleted]]

More information about the R-help mailing list