Discussion:
[Rcpp-devel] Starting R Interpreter from C++
Wolf Vollprecht
2017-06-12 08:11:32 UTC
Permalink
I am trying to run C++ tests from C++ directly.
It looks like I need to start the R interpreter for memory management etc.

So far I have achieved moderate success through:

int Rf_initEmbeddedR(int argc, char **argv)
{
Rf_initialize_R(argc, argv);
setup_Rmainloop();
return 1;
}


However, the code crashes with

Error: function 'dataptr' not provided by package 'Rcpp'
Fatal error: unable to initialize the JIT

Is there a simpler way to initialize the R environment from C++ (through
Rcpp?). Or any other insights?

Best,

Wolf
Romain Francois
2017-06-12 09:22:26 UTC
Permalink
You might be looking for RInside.
Post by Wolf Vollprecht
I am trying to run C++ tests from C++ directly.
It looks like I need to start the R interpreter for memory management etc.
int Rf_initEmbeddedR(int argc, char **argv)
{
Rf_initialize_R(argc, argv);
setup_Rmainloop();
return 1;
}
However, the code crashes with
Error: function 'dataptr' not provided by package 'Rcpp'
Fatal error: unable to initialize the JIT
Is there a simpler way to initialize the R environment from C++ (through Rcpp?). Or any other insights?
Best,
Wolf
_______________________________________________
Rcpp-devel mailing list
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Dirk Eddelbuettel
2017-06-12 11:11:33 UTC
Permalink
On 12 June 2017 at 11:22, Romain Francois wrote:
| You might be looking for RInside.

Exactly correct in the narrow sense of 'how to get R going from C++'.

On 12 June 2017 at 01:11, Wolf Vollprecht wrote:
| I am trying to run C++ tests from C++ directly. 
| It looks like I need to start the R interpreter for memory management etc.

The wider, normal sense of the question is, I suspect, how to add unit tests
to an R package such as your xtensor-r. Give me a day or two and I may get a
chance to add this to my variant of your project.

You generally do NOT want force an embedded R interpreter __as any Rcpp
project is already called from R__. Use CRAN as a repository of (as of
today) 1045 example packages. I don't think a single one embeds R for
testing. The RUnit (older, used by Rcpp itself) and testthat frameworks are
popular.

Dirk
--
http://dirk.eddelbuettel.com | @eddelbuettel | ***@debian.org
Wolf Vollprecht
2017-06-12 19:47:58 UTC
Permalink
RInside seems to have done the trick! Awesome.

I have no strong opinions on how to implement the tests. The only reason
why I wanted the embedded R solution is because we use it that way with
Python and Julia, and it gives us "raw C++" tests. In the future, we might
also have a xtensor-test package, that we can easily use to write tests for
all three languages (in C++) at the same time (through metaprogramming).

But we will definitly also add tests in R (as we have done with Python and
Julia, too).
It would be awesome if you have a chance to add some to your variant.
I am going to fix up the C++ tests that I've added to the "big" PR and make
sure that at least those we have right now work fine to establish a
baseline to work from.

Cheers!

Wolf
Post by Dirk Eddelbuettel
| You might be looking for RInside.
Exactly correct in the narrow sense of 'how to get R going from C++'.
| I am trying to run C++ tests from C++ directly.
| It looks like I need to start the R interpreter for memory management etc.
The wider, normal sense of the question is, I suspect, how to add unit tests
to an R package such as your xtensor-r. Give me a day or two and I may get a
chance to add this to my variant of your project.
You generally do NOT want force an embedded R interpreter __as any Rcpp
project is already called from R__. Use CRAN as a repository of (as of
today) 1045 example packages. I don't think a single one embeds R for
testing. The RUnit (older, used by Rcpp itself) and testthat frameworks are
popular.
Dirk
--
JJ Allaire
2017-06-12 20:15:02 UTC
Permalink
There is also a way to write C++ unit test with the catch framework and
have them added to the R test suite:
https://rdrr.io/cran/testthat/man/use_catch.html

Note this was originally built with integration with testthat in mind but
you can call it from any R test suite (docs on doing this are on the linked
to page).
Post by Wolf Vollprecht
RInside seems to have done the trick! Awesome.
I have no strong opinions on how to implement the tests. The only reason
why I wanted the embedded R solution is because we use it that way with
Python and Julia, and it gives us "raw C++" tests. In the future, we might
also have a xtensor-test package, that we can easily use to write tests for
all three languages (in C++) at the same time (through metaprogramming).
But we will definitly also add tests in R (as we have done with Python and
Julia, too).
It would be awesome if you have a chance to add some to your variant.
I am going to fix up the C++ tests that I've added to the "big" PR and
make sure that at least those we have right now work fine to establish a
baseline to work from.
Cheers!
Wolf
Post by Dirk Eddelbuettel
| You might be looking for RInside.
Exactly correct in the narrow sense of 'how to get R going from C++'.
| I am trying to run C++ tests from C++ directly.
| It looks like I need to start the R interpreter for memory management etc.
The wider, normal sense of the question is, I suspect, how to add unit tests
to an R package such as your xtensor-r. Give me a day or two and I may get a
chance to add this to my variant of your project.
You generally do NOT want force an embedded R interpreter __as any Rcpp
project is already called from R__. Use CRAN as a repository of (as of
today) 1045 example packages. I don't think a single one embeds R for
testing. The RUnit (older, used by Rcpp itself) and testthat frameworks are
popular.
Dirk
--
_______________________________________________
Rcpp-devel mailing list
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Wolf Vollprecht
2017-06-13 22:22:38 UTC
Permalink
Dear all,

thanks so much for your help. Our tests are up and running on Travis now
(thanks to RInside!).

We've discovered one issue, though, when compiling with Clang. It might be
of interest to you:
https://travis-ci.org/QuantStack/xtensor-r/jobs/242587636
I am not 100% sure if the issue comes from RCpp or from xtensor (I'll need
more time to investigate, this is just a FYI).

In file included from
/home/travis/build/QuantStack/xtensor-r/test/test_rarray.cpp:11:
In file included from
/home/travis/build/QuantStack/xtensor-r/inst/include/xtensor-r/rarray.hpp:18:
In file included from
/home/travis/build/QuantStack/xtensor-r/inst/include/xtensor-r/rcontainer.hpp:19:
In file included from
/home/travis/miniconda/lib/R/library/Rcpp/include/Rcpp.h:65:
In file included from
/home/travis/miniconda/lib/R/library/Rcpp/include/Rcpp/InternalFunction.h:30:
In file included from
/home/travis/miniconda/lib/R/library/Rcpp/include/Rcpp/InternalFunctionWithStdFunction.h:27:
In file included from
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/tr1/functional:39:
/usr/bin/../lib/gcc/x86_64-linux-gnu/4.9/../../../../include/c++/4.9/tr1/tuple:130:5:
error: declaration conflicts with target of using declaration already in
scope
class tuple : public _Tuple_impl<0, _Elements...>

Cheers,

Wolf
Post by JJ Allaire
There is also a way to write C++ unit test with the catch framework and
have them added to the R test suite: https://rdrr.io/cran/
testthat/man/use_catch.html
Note this was originally built with integration with testthat in mind but
you can call it from any R test suite (docs on doing this are on the linked
to page).
Post by Wolf Vollprecht
RInside seems to have done the trick! Awesome.
I have no strong opinions on how to implement the tests. The only reason
why I wanted the embedded R solution is because we use it that way with
Python and Julia, and it gives us "raw C++" tests. In the future, we might
also have a xtensor-test package, that we can easily use to write tests for
all three languages (in C++) at the same time (through metaprogramming).
But we will definitly also add tests in R (as we have done with Python
and Julia, too).
It would be awesome if you have a chance to add some to your variant.
I am going to fix up the C++ tests that I've added to the "big" PR and
make sure that at least those we have right now work fine to establish a
baseline to work from.
Cheers!
Wolf
Post by Dirk Eddelbuettel
| You might be looking for RInside.
Exactly correct in the narrow sense of 'how to get R going from C++'.
| I am trying to run C++ tests from C++ directly.
| It looks like I need to start the R interpreter for memory management etc.
The wider, normal sense of the question is, I suspect, how to add unit tests
to an R package such as your xtensor-r. Give me a day or two and I may get a
chance to add this to my variant of your project.
You generally do NOT want force an embedded R interpreter __as any Rcpp
project is already called from R__. Use CRAN as a repository of (as of
today) 1045 example packages. I don't think a single one embeds R for
testing. The RUnit (older, used by Rcpp itself) and testthat frameworks are
popular.
Dirk
--
_______________________________________________
Rcpp-devel mailing list
https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
Dirk Eddelbuettel
2017-06-13 23:11:16 UTC
Permalink
On 13 June 2017 at 15:22, Wolf Vollprecht wrote:
| thanks so much for your help. Our tests are up and running on Travis now
| (thanks to RInside!).

I am very happy for you that you got that sorted out and you that you got
scratch that itch -- but allow me mention once more we said here before.
Nobody here tests the way you do. You are putting the cart before the horse.

Test your C++ code from C++ with any one of the bazillion frameworks: catch
(as suggested by JJ who reminded us that it is available via testthat), or
google-test, or Boost test, or ...

Test the R integration from R via tests/ or either one of RUnit or testthat.

| We've discovered one issue, though, when compiling with Clang. It might be of

Minimal and reproducible reports on Rcpp are always welcome as an issue ticket.

Dirk
--
http://dirk.eddelbuettel.com | @eddelbuettel | ***@debian.org
Continue reading on narkive:
Loading...