[Rd] bindingIsLocked returns illogical logical
Seth Falcon
sfalcon at fhcrc.org
Mon May 15 17:23:32 CEST 2006
Prof Brian Ripley <ripley at stats.ox.ac.uk> writes:
> On Sun, 14 May 2006, Seth Falcon wrote:
>> I wonder if ScalarLogical should force 0/1:
>
> Not a good idea: what about the third value, NA?
Indeed, I should have been sleeping (or perhaps I was already :-)
Is it enough to check for NA_LOGICAL or should all NA_* values be
checked for? Is there an easier/better way to do this sort of check?
Index: Rinlinedfuns.h
===================================================================
--- Rinlinedfuns.h (revision 38060)
+++ Rinlinedfuns.h (working copy)
@@ -494,6 +494,8 @@
INLINE_FUN SEXP ScalarLogical(int x)
{
SEXP ans = allocVector(LGLSXP, 1);
+ if ((x != NA_LOGICAL) && (x != 0))
+ x = 1;
INTEGER(ans)[0] = x;
return ans;
}
Perhaps for completeness, even though at present they are identical,
NA_INTEGER should be in the checking...
INLINE_FUN SEXP ScalarLogical(int x)
{
SEXP ans = allocVector(LGLSXP, 1);
if ((x == NA_LOGICAL) || (x == NA_INTEGER))
x = NA_LOGICAL;
else if (x != 0)
x = 1;
INTEGER(ans)[0] = x;
return ans;
}
Or perhaps there is a better solution entirely.
+ seth
>
>> 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