Vineetha
Vineetha

Reputation: 177

R package with Fortran Source Code: how to make “Makevars” file under “pkgname/src/”?

Related to the solution of my past question, OS X package installation issue: Can't find gfortran 4.8 to build package, I have the Makevars in ~/.R/. This allows me to build the R package and work locally on my system.

Now I want to make this package portable. I tried moving this Makevars to src folder and got the following error:

 * installing *source* package ‘pkgname’ ...
 ** libs
 gfortran-4.8  -fPIC -Wall -g -O2  -c  epidata.f95 -o epidata.o
 make: gfortran-4.8: No such file or directory
 make: *** [epidata.o] Error 1
 ERROR: compilation failed for package ‘pkgname’
 * removing ‘/Users/Vineetha/Desktop/pkgname.Rcheck/pkgname’

How can I resolve this issue?

Upvotes: 1

Views: 1687

Answers (1)

Bhas
Bhas

Reputation: 1834

Ok I now think that I understand the problem.

You have used the gfortran from the gfortranbinaries page on the wiki.

You have adapted your ~/.R/Makevars/ so that the macros FC, F77 and FLIBS point to the correct binaries and libraries.

You move that Makevars to your package src folder to make your package portable. You are assuming that it will be portable. You assume (or hope) that the R package builder will respect your choice of compiler. However it doesn't work that way.

When R builds a package it will always use the compilers that were used for building the R version you are using. You cannot override the above macros in a package Makevars. Those macros can only be changed in a ~/.R/Makevars/.

The R version you are most likely using was compiled on OS X mavericks with a specially compiled gfortran 4.8.2.; that is what R is complaining about. It can be obtained from here. You would have to use the Terminal to unpack the compressed file to the correct place. However you can't just install that version of gfortran because it will partly overwrite your version 6.1. So do not do that!.

You need not worry about using gfortran 6.1 as you are doing. See page 57 of the (patched) R installation and administration manual.

It states that you can and may use the gfortran you are using with a binary version of R obtained from CRAN.

So there is no need to move your ~/.R/Makevars/ out of the way.

To check portability of your package you can send it to the winbuilder service. Or use a Linux virtual machine for example.

To keep a package with Fortran source portable don't use any extensions of that compiler and don't use Fortran extensions specific to that version of your compiler.

In short, you don't have to resolve the issue you mentioned. Just write portable code.

Upvotes: 4

Related Questions