Skip to content
Prev 20636 / 63421 Next

bindingIsLocked returns illogical logical

Prof Brian Ripley <ripley at stats.ox.ac.uk> writes:
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
Message-ID: <m2ves7ia6j.fsf@ziti.local>
In-Reply-To: <Pine.LNX.4.64.0605150803070.8993@gannet.stats.ox.ac.uk> (Brian Ripley's message of "Mon, 15 May 2006 08:05:32 +0100 (BST)")