<div dir="ltr">Thanks a lot for your quick response, Dirk. Instead of printing the vector values using std::cout I am planning to serialize those objects using saveRDS and trying to retrieve the stored values using readRDS. I am trying to make use of the RInside instance to make a call to R functions. Although the class variable is recognized as an integer in the below example, when I use readRDS it says unknown input format. Is there a method to serialize Rcpp objects using RInside from a testharness? <div><b><br></b></div><div><b>Example:</b><div>TEST(deepstate_test,datatype){<br>RInside R;<br>R["ms"] = 5;<br>std::string cmd = "cat(class(ms));saveRDS(ms,\"mtest.Rds\"); readRDS(\"mtest.Rds\")";<br>R.parseEval(cmd); <br>}<br></div><div><b>Output:</b></div><div>akhila@akhila-VirtualBox:~$ ./newtest<br></div><div><b>TRACE: Running: deepstate_test_datatype from newtest.cpp(6)<br>EXTERNAL: integer<br>EXTERNAL:  �<br>EXTERNAL: Error in readRDS("mtest.Rds") : unknown input format<br><br>terminate called after throwing an instance of 'std::runtime_error'<br>  what():  Error evaluating: cat(class(ms));saveRDS(ms,"mtest.Rds"); readRDS("mtest.Rds")<br>ERROR: Failed: deepstate_test_datatype</b><br></div><div><br></div><div>Also, I tried using the below code in my Cpp function. I still get the same unknown input format error. </div><div><br></div><div>Rcpp::NumericMatrix mat = RcppDeepState_NumericMatrix();<br>Environment base("package:base");<br>Function saveRDS = base["saveRDS"];<br>saveRDS(mat,Named("file","mat.RDs"));<br>Function readRDS = base["readRDS"];<br>readRDS("mat.RDs");<br></div><div><br></div><div>Any help is appreciated. Thanks in advance</div><div><br></div><div>Regards,</div><div>Akhila Chowdary Kolla</div><div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Sep 4, 2020 at 3:15 PM Dirk Eddelbuettel <<a href="mailto:edd@debian.org">edd@debian.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
On 4 September 2020 at 11:24, Akhila Chowdary Kolla wrote:<br>
| Hello Everyone,<br>
| <br>
| I am trying to use NA_REAL, NA_INTEGER, and R_NaN in my CPP code(doesn't<br>
| use R main). When I compile and run my code,* NA_REAL* it gives the value<br>
| as *nan* and *NA_INTEGER* gives the value as *-2147483648, and R_NaN as 0*.<br>
| <br>
| I used the following code(from Rcpp FAQ):<br>
| Rcpp::IntegerVector Missing_I() {<br>
|   Rcpp::IntegerVector v(1);<br>
|   v[0] = NA_INTEGER; // NA<br>
|   return v;<br>
| }<br>
| Rcpp::NumericVector Missing_N() {<br>
|   Rcpp::NumericVector v(4);<br>
|   v[0] = R_NegInf; // -Inf<br>
|   v[1] = NA_REAL; // NA<br>
|   v[2] = R_PosInf; // Inf<br>
|   v[3] = R_NaN; // nan<br>
|   return v;<br>
| }<br>
| <br>
| When I compile the functions using sourceCpp() I get the output as expected:<br>
| > sourceCpp("~/R/RcppDeepState/inst/extdata/filesave.cpp")<br>
| > Missing_I()<br>
| [1] NA<br>
| > Missing_N()<br>
| [1] -Inf   NA  Inf  NaN<br>
| <br>
| But when I compile the code using the TestHarness it gives me the following<br>
| output:<br>
| missing_n values: -inf nan inf 0<br>
| missing_i values: -2147483648<br>
| <br>
| I saved the above functions(Missing_I, Missing_N) in a header file and made<br>
| a call to those functions from the testharness:<br>
| <br>
| TEST(deepstate_test,datatype){<br>
| RInside();<br>
| Rcpp::IntegerVector missing_i = Missing_I();<br>
| std::cout <<"missing_i values: "<< missing_i << std::endl;<br>
| Rcpp::NumericVector missing_n = Missing_N();<br>
| std::cout <<"missing_n values: "<< missing_n << std::endl;<br>
| }<br>
| <br>
| How can I get the results as expected? Any help is appreciated.<br>
<br>
Am I understanding you correctly that you would like _the R behaviour_ but in<br>
a non-R context (such as a catch or Google gtest harness) ?  You can't as<br>
easily as R actively adds some extensions. I.e. IEEE 754 defines this for<br>
doubles, but "nobody" besides R does it for Int. So you would have to add<br>
your print function.<br>
<br>
Dirk<br>
<br>
-- <br>
<a href="https://dirk.eddelbuettel.com" rel="noreferrer" target="_blank">https://dirk.eddelbuettel.com</a> | @eddelbuettel | <a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a><br>
</blockquote></div>