[Rcpp-devel] Handling NAs in RcppMatrix
Leo Alekseyev
dnquark at gmail.com
Sat Feb 6 23:56:23 CET 2010
Howdy folks,
I started playing around with Rcpp recently, and so far haven't been
able to figure out how to detect NAs in a matrix that I pass to the
C++ code.
My test code looks something like this:
RcppExport SEXP rcpp_test(SEXP N1, SEXP V1, SEXP M1, SEXP parms) {
.......
RcppMatrix<double> m1(M1);// double mtx based on M1
RcppVector<double> v1(V1);// double vector based on V1
RcppParams rparam(parms); // parameter from R based on parms
RcppResultSet rs;
Rcpp::RObject n1sexp(N1);
double n1 = n1sexp.asDouble();
Rprintf("The value of isna is %d\n",R_IsNA(n1));
double element1 = v1(0);
if(R_IsNA(element1))
Rprintf("Found NA in vector!\n");
double m00 = m1(0,0);
if(R_IsNA(m00))
Rprintf("Found NA in matrix!\n");
................
The R_IsNA() appears to work fine on scalars and vectors, but fails to
detect NA present in a matrix. Is this a bug?.. feature?.. Is the
handling of missing values documented anywhere other than the R
Extensions manual?..
On a (probably) unrelated note, I get the following error when
compiling my C++ code:
Error in RcppCxx0xFlags() : could not find function "capture.output"
Calls: <Anonymous> -> cat -> RcppCxx0xFlags
However, the code seems to compile fine. The compilation script is simply
#!/bin/bash
export PKG_CPPFLAGS="-I. "$(r -e "Rcpp:::CxxFlags()" )
export PKG_LIBS=$(r -e "Rcpp:::LdFlags()" )
export CLINK_CPPFLAGS=$(r -e "Rcpp:::Cxx0xFlags()" )
R CMD SHLIB "$@"
Complete output from compilation is pasted below -- is this an error I
should be concerned about?..
./buildAndRun.sh rcpp_test.cpp --clean
Error in RcppCxx0xFlags() : could not find function "capture.output"
Calls: <Anonymous> -> cat -> RcppCxx0xFlags
Execution halted
g++ -I/usr/share/R/include -I/usr/local/lib/R/site-library/Rcpp/lib
-fpic -g -O2 -c rcpp_test.cpp -o rcpp_test.o
Error in RcppCxx0xFlags() : could not find function "capture.output"
Calls: <Anonymous> -> cat -> RcppCxx0xFlags
Execution halted
Error in RcppCxx0xFlags() : could not find function "capture.output"
Calls: <Anonymous> -> cat -> RcppCxx0xFlags
Execution halted
g++ -shared -o rcpp_test.so rcpp_test.o
-L/usr/local/lib/R/site-library/Rcpp/lib -lRcpp
-Wl,-rpath,/usr/local/lib/R/site-library/Rcpp/lib -L/usr/lib/R/lib -lR
Error in RcppCxx0xFlags() : could not find function "capture.output"
Calls: <Anonymous> -> cat -> RcppCxx0xFlags
Execution halted
Thanks in advance for any help (and please let me know if this is not
the correct mailing list for these sorts of questions!)
--Leo Alekseyev
More information about the Rcpp-devel
mailing list