<div dir="ltr"><div><br></div><div>Michael - </div><div><br></div><div>I modified your example to use Rcpp::exception.</div><div><br></div><div>I think this was implemented here:</div><div><a href="https://github.com/RcppCore/Rcpp/pull/663/">https://github.com/RcppCore/Rcpp/pull/663/</a><br></div><div><br></div><div>Kyle</div><div><br></div><div><br></div><div>```{r}</div><div>library(Rcpp)</div><div><br></div><div>sourceCpp(code='</div><div>          #include "Rcpp.h"</div><div>          </div><div>          // [[Rcpp::export]]</div><div>          Rcpp::NumericVector internal_function_name(Rcpp::NumericVector x){</div><div>          throw Rcpp::exception("My error message.", false);</div><div>          return x + 2;</div><div>          }')</div><div><br></div><div>add2 <- function(x){</div><div>  if(!is.numeric(x)){</div><div>    x <- as.numeric(x)</div><div>  }</div><div>  </div><div>  do.call(internal_function_name, list(x))</div><div>}</div><div><br></div><div>add2(1:5)</div><div>```</div><div><br></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 5, 2018 at 4:35 PM, Michael Weylandt <span dir="ltr"><<a href="mailto:michael.weylandt@gmail.com" target="_blank">michael.weylandt@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
Is there any (easy) way to get Rcpp::stop() to behave like<br>
base::stop(..., call.=FALSE)? That is, to just print the error message<br>
(possibly preceded by "Error: ") without the name of the calling<br>
function.<br>
<br>
Right now, the error message produced by an Rcpp::stop call returns<br>
info about the caller, which isn't helpful for my users. (I do a bit<br>
of trickery to build an argument list and then use do.call() to call<br>
the RcppAttributes-generated wrapper) I'm happy to put the function<br>
name in the error message, but I'd like to remove the unhelpful part.<br>
<br>
Here's an (admittedly awkward) minimal example:<br>
<br>
```{r}<br>
library(Rcpp)<br>
<br>
sourceCpp(code='<br>
#include "Rcpp.h"<br>
<br>
// [[Rcpp::export]]<br>
Rcpp::NumericVector internal_function_name(Rcpp::<wbr>NumericVector x){<br>
    Rcpp::stop("My error message.");<br>
    return x + 2;<br>
}')<br>
<br>
add2 <- function(x){<br>
    if(!is.numeric(x)){<br>
        x <- as.numeric(x)<br>
    }<br>
<br>
    do.call(internal_function_<wbr>name, list(x))<br>
}<br>
<br>
add2(1:5)<br>
```<br>
<br>
This prints: "Error in (function (x)  : My error message." I'm hoping<br>
to get "Error: My error message."<br>
<br>
Cheers,<br>
Michael<br>
______________________________<wbr>_________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-<wbr>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-<wbr>project.org/cgi-bin/mailman/<wbr>listinfo/rcpp-devel</a><br>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>Kyle Baron, PharmD, PhD</div><div>Senior Scientist<br>Metrum Research Group<br><br></div></div></div>
</div>