[Rcpp-devel] [ExternalEmail] Newbie question: RInside from within a Inline/Rcpp cxxfunction

Jeffrey Pollock jeffpollock9 at gmail.com
Fri Sep 28 16:24:58 CEST 2012


Would it be useful to consider using the Function class in Rcpp? You can
pass R functions in as arguments like so;

library(inline)
library(Rcpp)

example <- cxxfunction(signature(f_ = "Function"), body = '
                Rcpp::Function f(f_);
                Rcpp::NumericVector out = f(10, 1);
                return out;
                ', plugin = "Rcpp")

> example(rpois)
 [1] 2 0 1 3 1 1 1 0 1 0

Obviously you wouldn't want to pass R's rpois function in (as this is
already implement in Rcpp Sugar) but hopefully the example will make sense.

Jeff

On Fri, Sep 28, 2012 at 5:05 AM, <Dan.Pagendam at csiro.au> wrote:

> Apologies, in the previous email I meant to say:
>
>  "Is it possible for me to have my cxxfunction instantiate an object of
> class RInside within the C++ code?"
>
> NOT
>
> "Is it possible for me to have my cxxfunction instantiate an object of
> class RInline within the C++ code?"
>
>
> Dr Dan Pagendam
> OCE Postdoctoral Research Fellow
> CSIRO Mathematics, Informatics and Statistics
>
> Phone: +61 7 3833 5535 | Mobile: +61 4 3295 8551
> Email: Dan.Pagendam at csiro.au<mailto:Dan.Pagendam at csiro.au><mailto:
> Dan.Pagendam at csiro.au<mailto:Dan.Pagendam at csiro.au>> | http://www.csiro.au
> Postal Address: CSIRO Mathematics Informatics and Statistics, EcoSciences
> Precinct, PO Box 2583, Brisbane, QLD 4001
> Street Address: CSIRO Mathematics Informatics and Statistics, EcoSciences
> Precinct, 41 Boggo Road, Dutton Park, QLD 4102
>
>
>
> On 28/09/2012, at 1:48 PM, <Dan.Pagendam at csiro.au<mailto:
> Dan.Pagendam at csiro.au>> wrote:
>
> Hi,
>
> this is my first post here.  I've just started to explore the uses of
> Rcpp, Inline and RInside and must say that I think these are really
> fantastic tools, which I hope to use routinely in the future.
>
> I'm about to embark on writing some code, but before I do, I was hoping
> somebody can offer a quick "sanity check" for me and let me know if what I
> am proposing is achievable and sensible.
>
> Bascially, I would like to write a cxxfunction in R using Rcpp and Inline
> so that I can execute my C++ code easily from within R.  However, I'd like
> my C++ code comprising the cxxfunction to make use of the R language too.
>  Is it possible for me to have my cxxfunction instantiate an object of
> class RInline within the C++ code?  I guess what I'm getting at is, can I
> get R to call on a C++ function which in turn calls upon R code?
>
> I've looked at plenty of examples of code that use RInline and it seems
> that they are all just based around calling on R from with C++.  This is
> making me wonder if what I am suggesting above is either plain dumb or just
> not possible.
>
> Thanks in advance for your help,
>
> Dan
>
> Dr Dan Pagendam
> OCE Postdoctoral Research Fellow
> CSIRO Mathematics, Informatics and Statistics
>
> Phone: +61 7 3833 5535 | Mobile: +61 4 3295 8551
> Email: Dan.Pagendam at csiro.au<mailto:Dan.Pagendam at csiro.au><mailto:
> Dan.Pagendam at csiro.au><mailto:Dan.Pagendam at csiro.au<mailto:
> Dan.Pagendam at csiro.au>> | http://www.csiro.au
> Postal Address: CSIRO Mathematics Informatics and Statistics, EcoSciences
> Precinct, PO Box 2583, Brisbane, QLD 4001
> Street Address: CSIRO Mathematics Informatics and Statistics, EcoSciences
> Precinct, 41 Boggo Road, Dutton Park, QLD 4102
>
>
>
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org<mailto:
> Rcpp-devel at lists.r-forge.r-project.org>
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20120928/9be0cb9b/attachment.html>


More information about the Rcpp-devel mailing list