<div dir="ltr">Hello Bill,<div><br></div><div>Thanks for the information.When I run the specified commands on the generated mat.RDs file I get the following:</div><div><br></div><div>> file.exists("mat.RDs")<br>[1] TRUE<br>> file.size("mat.RDs")<br>[1] 37<br>> readBin("mat.RDs", what=raw(), n=20)<br> [1] 8b e0 62 60 60 60 66 60 66 03 62 56 20 93 81 35 34 c4 4d d7<br>> readBin(gzfile("mat.RDs","rb"), what=raw(), n=20)<br> [1] 8b e0 62 60 60 60 66 60 66 03 62 56 20 93 81 35 34 c4 4d d7<br>> <br></div><div><br></div><div>I used compress=TRUE in saveRDS function call while generating the file(mat.RDs) it still gives me the result starting with 8b instead of 1f. Please Advice.</div><div><br></div><div>Thanks,</div><div>Akhila Chowdary</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Sep 8, 2020 at 4:29 PM Bill Dunlap <<a href="mailto:williamwdunlap@gmail.com">williamwdunlap@gmail.com</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"><div dir="ltr">a) Does the 'rds' file you tried to make exist?<div>   file.exists("mat.RDs") </div><div>b) It should have a more than c. 10 bytes in it.</div><div>   file.size("mat.RDs")</div><div>c) It should start with the with the 2-byte "magic number" for gzip files, 1f 8b:</div><div>   readBin("mat.RDs", what=raw(), n=20)</div> [1] 1f 8b 08 00 00 00 00 00 00 06 8b e0 62 60 60 60 66 60 61 60<div>d) When unzipped it should start with the rds header, 58 0a, then version 3,</div><div>then the version of R that made it (4 0 2), and the earliest version of R that can</div><div>read it (3 5 0):<br>  readBin(gzfile("mat.RDs","rb"), what=raw(), n=20)<br> [1] 58 0a 00 00 00 03 00 04 00 02 00 03 05 00 00 00 00 06 43 50</div><div><div><br></div></div><div>Failure of d will give you the "unknown input format" error'.  Failure</div><div>of c means you used compress=FALSE in the call to saveRDS.</div><div><br></div><div>-Bill </div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Sep 8, 2020 at 4:11 PM Dirk Eddelbuettel <<a href="mailto:edd@debian.org" target="_blank">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 8 September 2020 at 16:03, Akhila Chowdary Kolla wrote:<br>
| Thanks a lot for your quick response, Dirk. Instead of printing the vector<br>
| values using std::cout I am planning to serialize those objects using<br>
| saveRDS and trying to retrieve the stored values using readRDS. I am trying<br>
| to make use of the RInside instance to make a call to R functions. Although<br>
| the class variable is recognized as an integer in the below example, when I<br>
| use readRDS it says unknown input format. Is there a method to serialize<br>
| Rcpp objects using RInside from a testharness?<br>
| <br>
| *Example:*<br>
| TEST(deepstate_test,datatype){<br>
| RInside R;<br>
| R["ms"] = 5;<br>
| std::string cmd = "cat(class(ms));saveRDS(ms,\"mtest.Rds\");<br>
| readRDS(\"mtest.Rds\")";<br>
| R.parseEval(cmd);<br>
| }<br>
| *Output:*<br>
| akhila@akhila-VirtualBox:~$ ./newtest<br>
| <br>
| <br>
| <br>
| <br>
| <br>
| <br>
| <br>
| *TRACE: Running: deepstate_test_datatype from newtest.cpp(6)EXTERNAL:<br>
| integerEXTERNAL: �EXTERNAL: Error in readRDS("mtest.Rds") : unknown input<br>
| formatterminate called after throwing an instance of 'std::runtime_error'<br>
| what():  Error evaluating: cat(class(ms));saveRDS(ms,"mtest.Rds");<br>
| readRDS("mtest.Rds")ERROR: Failed: deepstate_test_datatype*<br>
| <br>
| Also, I tried using the below code in my Cpp function. I still get the same<br>
| unknown input format error.<br>
| <br>
| 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>
| <br>
| Any help is appreciated. Thanks in advance<br>
<br>
That leaves me a little puzzled. No immediate suggestion.<br>
<br>
Restoring an R-written RDS with another R session should always work.  Strange.<br>
<br>
Dirk<br>
<br>
| Regards,<br>
| Akhila Chowdary Kolla<br>
| <br>
| On Fri, Sep 4, 2020 at 3:15 PM Dirk Eddelbuettel <<a href="mailto:edd@debian.org" target="_blank">edd@debian.org</a>> wrote:<br>
| <br>
| ><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<br>
| > 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<br>
| > 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<br>
| > 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<br>
| > 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<br>
| > 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>
| ><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>
_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org" target="_blank">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" rel="noreferrer" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a></blockquote></div>
</blockquote></div>