[R-SIG-Mac] ISNA(NA_REAL) == false?

Duncan Murdoch murdoch at stats.uwo.ca
Wed Jan 17 13:37:41 CET 2007


On 1/17/2007 7:05 AM, David Faden wrote:
> Hi,
> 
> Is it expected that ISNA(NA_REAL) will evaluate to false?

No, but what it does is compare to something in memory.  If R hasn't 
initialized, that location won't be set, and you'll get wrong results.

See the "Using these functions in your own C code" for instructions on 
how to build things for your sort of use.  Your code was linked as 
though it would be called from a running version of R, which had handled 
the initialization.

Duncan Murdoch

  From Writing
> R Extensions, I'd expected it instead to evaluate to true, but this
> seems not to be the case. What value should one use to represent an NA
> in native code if not NA_REAL? (I am trying to test some code by using
> a small C++ application to call it. Ultimately the code will be called
> from within R, but I'm hoping to get more information out of gdb this
> way. To get this to work, though, I need to be able to get the
> equivalent of expressions such as rep(c(NA, 1), 50), in my native
> code.)
> 
> isnan, etc., seem to be available.
> 
> Below is some example code and its output on my computer, along with
> some version info. Thanks much for any insights into what's going on.
> 
> David
> ----
> dfaden at iastate.edu
> AIM: pitulx
> ----
> 
> na.cpp:
> #include <iostream>
> #include <R_ext/Arith.h>
> 
> int main()
> {
>   if (!ISNA(NA_REAL)) {
>     std::cout << "Hm.\n";
>   }
> }
> 
> Output:
> $ g++ -I/Library/Frameworks/R.framework/Versions/Current/Resources/include
> -L/Library/Frameworks/R.framework/Versions/Current/Resources/lib -lR
> na.cpp
> $ R CMD ./a.out
> Hm.
> 
> ----
> 
> g++ version:
> i686-apple-darwin8-g++-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build 5250)
> 
> R version:
> platform       i386-apple-darwin8.8.1
> arch           i386
> os             darwin8.8.1
> system         i386, darwin8.8.1
> status
> major          2
> minor          4.1
> year           2006
> month          12
> day            18
> svn rev        40228
> language       R
> version.string R version 2.4.1 (2006-12-18)
> 
> I'm running Mac OS X 10.4.8.
> 
> _______________________________________________
> R-SIG-Mac mailing list
> R-SIG-Mac at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-mac



More information about the R-SIG-Mac mailing list