[Rd] bindingIsLocked returns illogical logical
Prof Brian Ripley
ripley at stats.ox.ac.uk
Mon May 15 17:43:24 CEST 2006
On Mon, 15 May 2006, Seth Falcon wrote:
> 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?
NA_LOGICAL and NA_INTEGER are the same value, and only NA_LOGICAL should
occur here. I used
/* As from R 2.4.0 we check that the value is allowed. */
INLINE_FUN SEXP ScalarLogical(int x)
{
SEXP ans = allocVector(LGLSXP, 1);
if (x == NA_LOGICAL) INTEGER(ans)[0] = NA_LOGICAL;
else INTEGER(ans)[0] = (x != 0);
return ans;
}
mainly because its intentions are crystal clear.
>
> 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
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
>
--
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