[R-pkg-devel] R_registerRoutines, etc.

Rolf Turner r.turner at auckland.ac.nz
Mon Apr 24 01:53:38 CEST 2017


On 24/04/17 11:36, Duncan Murdoch wrote:
> On 23/04/2017 6:18 PM, Rolf Turner wrote:
>> On 23/04/17 23:05, Duncan Murdoch wrote:
>>
>>>>>
>>>>> Looks like
>>>>>
>>>>> extern void F77_NAME(mnnd)(double *, double *, int *, double *,
>>>>> double *);
>>>>>
>>>>> to me.
>>
>> One more (I hope it's the last!) question:
>>
>> One of my subroutines has an argument of type *logical*.  There is no
>> logical type in C.  So, since I am perforce using C-speak, I cannot
>> change "void *" to "void logical".
>>
>
> For questions like this, see Writing R Extensions section 5.2. "Logical"
> in R is "int *" in C, and "INTEGER" in Fortran.
>
> This is important:  *there is no way to pass a Fortran "LOGICAL" from R
> to Fortran*.
>
> The issue is that different Fortran compilers store LOGICAL in different
> ways.  Some are equivalent to int with 0 for FALSE, all else for TRUE,
> but not all are.  So don't rely on it.
>
> If you need to call a Fortran subroutine that takes a LOGICAL argument,
> you need to write another Fortran subroutine that takes an INTEGER
> argument.  Then compute "arg NE 0" (or whatever the Fortran version is
> for testing not equal to zero) and pass that to the original routine.

Hoo-boy!!!  Some serious code-rewriting called for!

Thanks for setting me straight on this.

Is it possible that R CMD check could be set up to issue an error, or at 
least a warning, if it finds "logical" or "as.logical" in the argument 
lists of calls to .Fortran()?

Seems like it would be a Good Idea if it is indeed possible.

cheers,

Rolf

-- 
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276



More information about the R-package-devel mailing list