Martin Smith
Martin Smith

Reputation: 4077

R is using the mingw_32 to compile packages for 64-bit architecture

Periodically – I think whenever I update R – I have problems installing packages from source on my 64-bit Windows machine.

Today I'm trying to install a package using devtools::install_github(). The installation proceeded fine on my laptop, but my not on my desktop, which can install the package under *** arch - i386, but under *** arch - x64, which reports the error message

C:/PROGRA~1/R/R-34~1.4/bin/x64/R.dll: file not recognized: File format not recognized

The command that caused the error is

C:/Rtools/mingw_32/bin/g++ -shared -s -static-libgcc -o PACKAGENAME.dll [...]

I believe that the error is arising because R is using mingw_32 to attempt to compile a 64-bit package. The question is, where can I tell R to use mingw_64? I've already checked all the places that I can recall:

R must be looking somewhere else to decide which compiler to use... but where?

Upvotes: 5

Views: 2670

Answers (3)

Martin Smith
Martin Smith

Reputation: 4077

Via R CMD check not looking for gcc in Rtools directory:

R was looking in C:/Users/MYUSERNAME/Documents/.R/Makevars for the value of BINPREF. Deleting the contents of this file removed the incorrect location.

$RPATH/etc/i386/Makeconf is re-created with each new installation of R, and contains the line BINPREF ?= c:/Rtools/mingw_32/bin/.
The ?= operator will set the value of BINPREF if it is not already set, as it was in the Makevars file mentioned above. So replacing ?= with = will work until a new version of R is installed and the Makeconf file is overwritten – updating, or uninstalling, R will not modify the Makevars file in the User directory.

Upvotes: 3

yadeem
yadeem

Reputation: 31

BINPREF ?= c:/Rtools/mingw_64/bin/

remove ? before =

Upvotes: 0

chinsoon12
chinsoon12

Reputation: 25225

If you start digging from devtools::install_github, it will lead you through the following functions:

devtools::install_github
devtools:::install_remotes
devtools:::try_install_remote
devtools:::install_remote
devtools:::install
devtools:::check_build_tools
devtools:::setup_rtools
devtools:::scan_path_for_rtools

And when you run the following code:

devtools:::scan_path_for_rtools(TRUE)
devtools:::setup_rtools(debug=TRUE)

Most likely, it is saying that Rtools is not currently installed. (Yes, a bit counterintuitive given that you already have it installed in C:/Rtools but maybe not registered in registry)

To fix it, you will need to run (which is in essence the solution in Rtools is not being detected from RStudio)

Sys.setenv(PATH=paste0("C:\\Rtools\\bin;", Sys.getenv("PATH")))
devtools:::set_rtools_path(structure(list(path="c:/Rtools/mingw_64/bin", version=3.4), class="rtools"))
devtools:::set_rtools_path(structure(list(path="c:/Rtools/mingw_32/bin", version=3.4), class="rtools"))

Please let me know if this works.

Upvotes: 0

Related Questions