Skip to content

Windows installation

kaskr edited this page Aug 18, 2022 · 8 revisions

OLD - OUTDATED!

IF YOU KNOW HOW, PLEASE FEEL FREE TO ADAPT THESE INSTRUCTIONS TO NEW RTOOLS - THANKS!

Installation of TMB on Windows

(Instructions provided by Robert O'Boyle)

  1. Ensure that latest version of Rstudio, R & Rtools are installed and can be accessed through Rstudio

    1. If not, uninstall R & Rtools
    2. Check if Rtools folder exists and if so, delete
  2. Install latest version of R

  3. Install compatible version of Rtools available on CRAN; during installation

    1. Unclick 32 bit Rtools
    2. Click edit system PATH; should have
      1. c:\Rtools\bin;
      2. c:\Rtools\mingw_64\bin;

    Note that having c:\Rtools\mingw_32\bin; in the path as well as the _64\bin in the path works for TMB but creates a conflict with ADMB.

  4. Open R and type install.packages("TMB")

    1. This installs the TMB package
  5. If there are matrix package inconsistencies, re-install as install.packages("Matrix").

  6. Check that TMB runs in R.

    1. Open test files (e.g. linreg files) and ensure that TMB runs
    2. After running one model, execute precompile(); next model run will complete precompilation
    3. When installing and upgrading R & Rtools, make sure all .o, .0s and .dll files from previous models are removed. They will no longer be compatible with the upgrades

Windows debugging

There are sometimes problems getting gdbsource working on Windows. Using Rtools34 the following steps were required. Assuming we are running 64 bit R, first verify we are accessing the 64 bit versions of g++, gdb and Rterm by running

> shell("where g++")
c:\Rtools\mingw_32\bin\g++.exe
> shell("where gdb")
C:\Rtools\bin\gdb.exe
c:\Rtools\mingw_32\bin\gdb.exe
> shell("where Rterm")
INFO: Could not find files for the given pattern(s).

There first occurrence is what matters i.e. must be the 64 bit version. In this case we have a problem. We can modify the PATH from within R using this function:

fixwinpath <- function() {
  PATH <- Sys.getenv("PATH")
  PATH <- paste0(R.home(), "/bin/x64;", PATH)
  PATH <- paste0("c:/Rtools/mingw_64/bin;", PATH)
  Sys.setenv(PATH=PATH)
}

After running fixwinpath() you should get the correct 64 bit locations when running the above shell commands. To get gdbsource working you must

  • Put fixwinpath() at the top of your R script.
  • Remember to compile with compile(file, "-O1 -g", DLLFLAGS="") (Without DLLFLAGS="" you won't get line number info)
  • If you are using a precompile() version of TMB further add libtmb=FALSE to the compile command.

Additional hints

  • fixwinpath() works per session hence does not change the global PATH. It may be preferable to add it to ~/.Rprofile so that it is invoked for every R session.