[Rcpp-devel] Call R function

Douglas Bates bates at stat.wisc.edu
Wed Jun 20 16:20:45 CEST 2012

I enclose a rewrite of your function
-------------- next part --------------

R version 2.15.0 (2012-03-30)
Copyright (C) 2012 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> require(inline)
Loading required package: inline
> code <- '
+ Function      fun(ff);
+ NumericVector par(pp);
+ NumericVector par1(par), par2(par);
+ const double a(2.), b(3.);
+ par1[0] *= a;
+ par2[0] *= b;
+ NumericVector f1(fun(par1)), f2(fun(par2));
+ return wrap(Rf_runif(0., 1.) <= (f1[0] - f2[0]));
+ '
> RcppGibbs <- cxxfunction(signature(pp = "numeric", ff="function"),
+                          code, plugin="Rcpp")
> ff <- function(par) dnorm(par[1]) * dnorm(par[2])
> RcppGibbs(3., ff)
> proc.time()
   user  system elapsed 
  4.888   0.388   5.390 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.R
Type: application/octet-stream
Size: 442 bytes
Desc: not available
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20120620/220db0b9/attachment.obj>

More information about the Rcpp-devel mailing list