[R-SIG-Mac]Re: A mac/win difference in R1.4.0

Luke Tierney luke@stat.umn.edu
Mon, 14 Jan 2002 19:49:29 -0600


The windows behavior is the correct one.  On the Carbon Mac version

if (as.logical(NA)) 1 else 0
if (logical(0)) 1 else 0

both return 0 instead of signaling an error.

I think the problem may be the declaration of Rboolean in Rmath.h as

typedef enum { FALSE = 0, TRUE } Rboolean;

In fact, there is a third possible value, NA_LOGICAL, which is

#define NA_LOGICAL	R_NaInt

and R_NaInt is usually INT_MIN.

I suspect the MPW compiler Stefano uses gives sizeof(Rboolean) = 1 but
most other compilers use sizeof(Rboolean) = sizeof(int).  There may be
a switch to MPW C that tells it to allocate enums as full int's.  On
the other hand, I don't know the legalities here but I suspect that
this behavior is legal, so we might run into it elsewhere.  If so we
should fix it in the sources.  Not sure of the best way to do it.
Something like

typedef enum { FALSE = 0, TRUE = 1, NA_LOGICAL = NA_INTEGER } Rboolean;

would do in spirit, but NA_INTEGER expands to R_NaInt, so that would
need some further juggling.

luke

On Mon, Jan 14, 2002 at 07:31:08PM -0500, Peter Macdonald wrote:
> Here is a simpler example of the inconsistency:
> 
> On Windows R 1.4.0
> 
> > if(NULL == "A") print("Yes") else print("No")
> Error in if (NULL == "A") print("Yes") else print("No") :
>         missing value where logical needed
> 
> On Mac R 1.4.0
> 
> > if(NULL == "A") print("Yes") else print("No")
> [1] "No"
> 
> *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
>  Peter D.M. Macdonald, D.Phil.      McMaster University
>  Professor of Math & Statistics     Hamilton, Ontario, Canada L8S 4K1
> *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
> 
> 
> On Sat, 12 Jan 2002, Peter Macdonald wrote:
> 
> > Can anyone give me insight on this or suggest a better way? Thanks!
> >
> > On the Mac I can write
> >
> >     invmat <- try(solve(hessian/2))
> >     if (class(invmat) == "try-error")
> >         invmat <- matrix(NA, nrow = nrow(hessian), ncol = ncol(hessian))
> >
> > But in Windows I have to add a test for null class or I get a fatal error
> > at the == when class is null
> >
> >     invmat <- try(solve(hessian/2))
> >     if (!is.null(class(invmat)))
> >         if (class(invmat) == "try-error")
> >             invmat <- matrix(NA, nrow = nrow(hessian), ncol =
> > ncol(hessian))
> >
> >
> > *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
> >  Peter D.M. Macdonald, D.Phil.      McMaster University
> >  Professor of Math & Statistics     Hamilton, Ontario, Canada L8S 4K1
> > *~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*
> >
> >
> >
> 
> _______________________________________________
> R-SIG-Mac mailing list
> R-SIG-Mac@stat.math.ethz.ch
> http://www.stat.math.ethz.ch/mailman/listinfo/r-sig-mac

-- 
Luke Tierney
University of Minnesota                      Phone:           612-625-7843
School of Statistics                         Fax:             612-624-8868
313 Ford Hall, 224 Church St. S.E.           email:      luke@stat.umn.edu
Minneapolis, MN 55455 USA                    WWW:  http://www.stat.umn.edu