[Rd] bindingIsLocked returns illogical logical

Prof Brian Ripley ripley at stats.ox.ac.uk
Mon May 15 09:05:32 CEST 2006


On Sun, 14 May 2006, Seth Falcon wrote:

> Martin Morgan <mtmorgan at fhcrc.org> writes:
>
>> bindingIsLocked applied to a locked binding returns a 'logical' that
>> is niether true nor false.
>
> Is this a philosophical question? :-)

But there is such a value defined for R logical vectors.

> Here's what I think is going on:
>
> BINDING_IS_LOCKED does not return 0/1, but the result of a bit op that
> will be either 0 or some int where bit 14 is set.
>
> The behavior you describe is consistent with a logical value escaping
> to R where the underlying int is some x > 1.
>
> I wonder if ScalarLogical should force 0/1:

Not a good idea: what about the third value, NA?

> Index: include/Rinlinedfuns.h
> ===================================================================
> --- include/Rinlinedfuns.h      (revision 38060)
> +++ include/Rinlinedfuns.h      (working copy)
> @@ -494,7 +494,7 @@
> INLINE_FUN SEXP ScalarLogical(int x)
> {
>     SEXP ans = allocVector(LGLSXP, 1);
> -    INTEGER(ans)[0] = x;
> +    INTEGER(ans)[0] = (x == 0) ? 0 : 1;
>     return ans;
> }
>
> Otherwise, I think do_bndIsLocked needs to make a similar operation
> before calling ScalarLogical.  But preventing these all purpose
> logicals from escaping would seem to be a good argument for changing
> ScalarLogical.

I think it needs to handle NAs.

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list