Bug 15878 - Check for valid logical values from .C is broken
Summary: Check for valid logical values from .C is broken
Alias: None
Product: R
Classification: Unclassified
Component: Language (show other bugs)
Version: R 3.1.0
Hardware: All All
: P5 normal
Assignee: R-core
Depends on:
Reported: 2014-07-11 19:47 UTC by Radford Neal
Modified: 2017-10-23 10:48 UTC (History)
2 users (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Radford Neal 2014-07-11 19:47:46 UTC
Help for .C says that logical values returned are checked for validity, with anything other than TRUE, FALSE, and NA converted to TRUE.

Actually, no attempt to do this is done when DUP = FALSE.  If this is intended, it should be made clear in the documenation.

When DUP = TRUE, an attempt is made, but it works only if no duplication was needed (because NAMED was zero).  When a duplicate is made, the check for valid logical values mistakenly looks at the original vector, not the duplicate.

For example, with R-3.1.1 (or any version from R-2.15.1 on):

In test-docC-logical.c:   void test (int *a) { a[0] = 2; }


print (.C("test",a=c(T,F))$a)
print (.C("test",a=c(T,F))$a + 1)

x <- c(T,F)
print (.C("test",a=x)$a)
print (.C("test",a=x)$a + 1)

The last value printed has a "3", which shouldn't be possible from adding 1 to a logical value.
Comment 1 Tomas Kalibera 2017-10-23 10:48:17 UTC
Thanks for the report, the part of the bug that still applies to the current version of R has been now fixed in 73583.