5

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-3.4.4/etc/x64/Makeconf states BINPREF ?= c:/Rtools/mingw_64/bin/
  • My system PATH (verified from within R using Sys.getenv('PATH')) includes mingw_64 ahead of mingw_32.

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

Martin Smith
  • 3,687
  • 1
  • 24
  • 51
  • do you want to install the 32bit library as well or do you just want to install the 64bit lib? – chinsoon12 Apr 18 '18 at 09:03
  • I'd prefer to have both the 32-bit and the 64-bit installed, but a solution that allows me to get up and running with just the 64-bit version would still be very useful! – Martin Smith Apr 18 '18 at 09:06
  • 2
    ok maybe pass in `INSTALL_opts='--no-multiarch'` into `install_github` – chinsoon12 Apr 18 '18 at 09:08
  • 1
    `devtools::install_github(package, args='--no-multiarch')` seemed to do the trick, thanks – much appreciated. It'd still be nice to know the solution to the underlying problem, though. – Martin Smith Apr 18 '18 at 09:18
  • 1
    see also https://bugs.r-project.org/bugzilla/show_bug.cgi?id=16919 and also https://stackoverflow.com/questions/33103203/rtools-is-not-being-detected-from-rstudio – chinsoon12 Apr 18 '18 at 09:25

3 Answers3

3

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.

Martin Smith
  • 3,687
  • 1
  • 24
  • 51
  • 1
    This issue was driving me crazy after updating to rtools 4.0 and your suggestion fixed it. I believe that I populated the "Marevars" file when I complied rstan, and deleting those files cleaned it up. – BKay May 07 '20 at 18:49
0

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.

chinsoon12
  • 25,005
  • 4
  • 25
  • 35
  • `scan_path_for_rtools` finds `Rtools version 3.4.0.1964`, and `setup_rtools` reports the same. `set_rtools_path` returns `Error: is.rtools(rtools) is not TRUE` – Martin Smith Apr 18 '18 at 10:52
  • 1
    have fixed it. i actually have a diff problem from you. i get NULL for `scan_path_for_rtools` and `setup_rtools`. will be interested to know how you will solve this – chinsoon12 Apr 19 '18 at 00:32
0
BINPREF ?= c:/Rtools/mingw_64/bin/

remove ? before =

Zoe
  • 27,060
  • 21
  • 118
  • 148
yadeem
  • 31
  • 3
  • 3
    Describe something about your answer will help others to easily catch your answer. refer https://stackoverflow.com/help/how-to-answer – Angel F Syrus Jun 07 '19 at 09:41