[R] Mysterious seg fault --- SOLVED

Rolf Turner r@turner @end|ng |rom @uck|@nd@@c@nz
Mon Aug 13 11:54:06 CEST 2018


On 13/08/18 20:45, Henrik Bengtsson wrote:

> On Mon, Aug 13, 2018 at 3:51 AM Rolf Turner <r.turner using auckland.ac.nz> wrote:
>>
>>
>> OK everybody!  You can relax.  :-) I managed to spot the loony.  After
>> mucking around with valgrind, and before trying gdb, I had one more look
>> at my code and *finally* saw the stupid thing that I had been doing.
>>
>> In the call to .Fortran() I had a line
>>
>>       nphi=as.integer(nphi),
>>
>> but "nphi" was nowhere defined (!!!) in the R code.  The name "nphi"
>> appeared as an argument in the Fortran subroutine in question, but was
>> nowhere actually *used*!!!
> 
> Didn't R CMD check pick this up, that is, didn't it report that 'nphi'
> is a "global" variable?

No it didn't.  The name only appears in the call to .Fortran().  I think 
if it appeared in a call to an ordinary garden-variety R function then a 
warning would have been issued.

Such a lapse would be hard for R CMD check to pick up.  E.g

    nphi=integer(1),

would be OK in a call to .Fortran (which would allow a value of nphi, 
calculated within the called subroutine, to be *returned*) whereas

    nphi=as.integer(nphi),

causes trouble when nphi has never been defined (as I found out after a 
great expenditure of time and torn-out hair).  In the former instance it 
doesn't matter an FTCF whether nphi has been defined or not.

cheers,

Rolf

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




More information about the R-help mailing list