-
-
Notifications
You must be signed in to change notification settings - Fork 208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modules vignette review #982
Modules vignette review #982
Conversation
More on the issue with the The following is a minimal example #include <Rcpp.h>
typedef std::vector<double> vec;
// Free function wrappers to work around errors
// error: call of overloaded
// ‘method(const char [7], <unresolved overloaded function type>)’ is ambiguous
void vec_resize (vec* obj, int n) {
obj->resize(n);
}
// error: no matching function for call to
// ‘Rcpp::class_<std::vector<double> >::method(const char [10], <unresolved overloaded function type>)’
void vec_push_back (vec* obj, double value) {
obj->push_back(value);
}
RCPP_MODULE(mod_vec) {
using namespace Rcpp;
class_<vec>("vec")
.constructor<int>()
// exposing member functions
.method("resize", &vec::resize)
// .method("resize", &vec_resize)
.method("push_back", &vec::push_back)
// .method("push_back", &vec_push_back)
;
} With compilation errors (Ubuntu 18.04, compiler details: void push_back (const value_type& val);
void push_back (value_type&& val);
void resize (size_type n);
void resize (size_type n, const value_type& val); This does not seem to be supported by |
Lovely stuff. I will make some time to review. Trying to get some other things out the door first so may take a few days. But first off ... big thanks for this! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great. I made a few remarks for when @eddelbuettel looks over it.
into the package namespace: | ||
|
||
```{r} | ||
loadModule("yada", TRUE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps switch this to a namespace function call?
loadModule("yada", TRUE) | |
Rcpp::loadModule("yada", TRUE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is surely a valid point, although this approach does not seem to be used across other Rcpp vignettes.
vignettes/Rcpp-modules.Rmd
Outdated
```{r, echo=FALSE,eval=TRUE} | ||
options( prompt = " ", continue = " " ) | ||
``` | ||
|
||
```{r, eval=FALSE} | ||
```{r} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like there was also a need to add:
import(methods)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I double-checked using the package produced by Rcpp::Rcpp.package.skeleton()
, removed the DESCRIPTION and NAMESPACE imports of methods
and things seem to still work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for checking that. I will merge this PR but that whole aspect may be worth looking into in another ticket. This changed over the years, and maybe describing just one simple (working) setup is best.
@eddelbuettel, @coatless, I was happy to provide my small contribution after being a happy user for quite some time. |
This is really good work, and I like it a lot. I didn't get to running it though. I think we should work out what we want the sections / questions you labeled as 'CHECK-PR' to say before we merge. |
I truly apologize for taking so long. Life gets in the way at times. My verdict is mostly two thumbs way up. I would just ask for one more pass, removing all the CHECK-PR as detailed below. I may still have overlooked some issues, but my quick notes are below. PS We also moved Comments:
|
* As a preliminary step before reviewing the specific section about packges. * General refinement to make it easier for a user to follow and run the examples. * Now all inline examples assume fxx (clearly stated) and explicitly call Module(), to make the examples closer to self-contained. * Also fixed minor typos.
* World was not already included in the examples above.
* Inline examples with R code now have a non-included chunk creating the assumed relevant fx object based on the C++ code in previous named chunk(s). * The document has gained a parameter `eval` in the YAML header, that can be set to TRUE to optionally run the examples. * This revealed compilation errors with the std::vector example, fixed with a workaround, to be discussed upon PR.
* Focus on recommended usage via loadModule with example * General review, also covering exports. * New section about using the convenient sourceCpp.
* \proglang all the way. * \textsl{Rcpp modules} everywhere but in their own section. * Consistent usage of inline C++ elements.
* Make evaluation even less intrusive.
* Removed parameters for evaluating chunks, restored evaluation as before, keeping named Rcpp chunks. * Finalized comment about resize and push_back workarounds for C++11. * Referred to Rcpp attributes vignette for sourceCpp. * Removed mustStart=TRUE (undocumented), the example works without. * Removed left-over style option chunks not needed.
7d3fb4f
to
9832314
Compare
@eddelbuettel, @coatless, thanks for your feedback. Back to connected life after a long weekend, I have addressed the CHECK-PR points in 9832314 as suggested above, with details in the commit comment. I have rebased the branch, although squash-merging might actually be a good idea. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Review of the Rcpp-modules vignette, with major focus on the usage in packages, as a follow-up of #976 (comment)
A (not so short) summary of the changes:
Replaced sparse references to packages across a few existing examples in the Rpp Modules section with a pointer to the specific section at beginning.
Introduced a new sub-section about usaging
sourceCpp()
as an alternative tocxxfuntion()
+getDynLib()
.Package section reviewed with focus on recommended loading via
loadModule()
Improvements and harmomization of existing examples in section Rcpp Modules
fx
(clearly stated) and explicitly callModule()
, to make them close to self-contained.World
class module in S4 dispatch example for completeness.fx
object based on the C++ code in previous named chunk(s).eval
andresults
in the YAML header to control evaluating the examples on demand (e.g. Knit with parameters...).std::vector
example, which I fixed with a workaround to be discussed.Fixed a few tyops + batch cosmetic alignment:
\proglang
all the way.\textsl{Rcpp modules}
everywhere but in their own section.I left a few explicit comments marked as
CHECK-PR
to have some pointers for the PR discussion.