[R-pkg-devel] Virtual C++ functions
Greetings, Suppose I wanted to develop a package with C++ code that contains virtual functions which the package user should define.It's assumed that evaluation is expensive so we do not want to define these in R and then call these R-functions from C++. Is this a reasonable idea with a standard solution?Are there packages that do this? Thanks in advance for all answers, Michael Meyer [[alternative HTML version deleted]] __ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel
Re: [R-pkg-devel] Virtual C++ functions
On 15/11/2023 4:37 a.m., Michael Meyer via R-package-devel wrote: Greetings, Suppose I wanted to develop a package with C++ code that contains virtual functions which the package user should define.It's assumed that evaluation is expensive so we do not want to define these in R and then call these R-functions from C++. Is this a reasonable idea with a standard solution?Are there packages that do this? Thanks in advance for all answers, I think you would be better off having your package evaluate R functions. If that's too slow, the user could use Rcpp or hand programming to put most of the computation into C++ or C code. It seems unlikely the overhead of passing the results from the user's C++ code through R would be significant if the computations themselves were slow. On the other hand, the user has the opportunity of prototyping in R, which may turn out to be fast enough. To get the prototyping possibility with your approach, you'd need to write and maintain two interfaces: C++ to C++ and C++ to R. One situation where this might be worth the trouble would be if you expect the user's function to be fast, but your code needs to call it a huge number of times, so the overhead adds up. Duncan Murdoch __ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel
Re: [R-pkg-devel] Virtual C++ functions
Le 15/11/2023 à 10:37, Michael Meyer via R-package-devel a écrit : Greetings, Suppose I wanted to develop a package with C++ code that contains virtual functions which the package user should define.It's assumed that evaluation is expensive so we do not want to define these in R and then call these R-functions from C++. Hm, virtual C++ functions are defined at compilation time. Their binding is done at runtime but at compilation time they must be already defined. So, how a package user (who already installed and therefor compiled your package) could define them? Moreover in R? Or may be you mean that a user import your C++ code and define his own derived function based on your virtual functions in his C++ code? Or, another option, you call "virtual function" what is usually called "callback function" like e.g. a function searching for roots of any user defined function and taking it as a parameter. This latter is a callback function. Could you precise what you mean by "virtual function" and "package user should define"? Best, Serguei. Is this a reasonable idea with a standard solution?Are there packages that do this? Thanks in advance for all answers, Michael Meyer [[alternative HTML version deleted]] __ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel __ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel
Re: [R-pkg-devel] Virtual C++ functions
On Wed, 15 Nov 2023 at 12:45, Michael Meyer via R-package-devel wrote: > > Greetings, > Suppose I wanted to develop a package with C++ code that contains virtual > functions which the package user should define.It's assumed that evaluation > is expensive so we do not want to define these in R and then call these > R-functions from C++. > Is this a reasonable idea with a standard solution?Are there packages that do > this? > Thanks in advance for all answers, Not sure if I understand what you are after, but the small RcppXPtrUtils package may be helpful. It provides two things: a utility to compile and wrap a C++ function provided by the user, and another one to check that the signature is correct. See: https://gallery.rcpp.org/articles/passing-cpp-function-pointers-rcppxptrutils/ -- Iñaki Úcar __ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel
Re: [R-pkg-devel] Virtual C++ functions
I believe RcppNumerical is doing this. Best Henrik > Am 15.11.2023 um 10:37 schrieb Michael Meyer via R-package-devel > : > > Greetings, > Suppose I wanted to develop a package with C++ code that contains virtual > functions which the package user should define.It's assumed that evaluation > is expensive so we do not want to define these in R and then call these > R-functions from C++. > Is this a reasonable idea with a standard solution?Are there packages that do > this? > Thanks in advance for all answers, > > Michael Meyer > [[alternative HTML version deleted]] > > __ > R-package-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-package-devel __ R-package-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-package-devel