[Rcpp-devel] [Rcpp] How can i call a R function in Cpp source code?

Dirk Eddelbuettel edd at debian.org
Tue Aug 5 17:23:03 CEST 2014


On 5 August 2014 at 23:07, super wrote:
| I am sorry for that, i  understand you.
| I think i should read your book  seamless R and C++ ... first. I shoudn't just
| want to get a quick guide which maybe convinient to me but the oppsite to you .
| BTW, i am a student from SJTU in china,and Google can't be used in china now. I

I used "Google" as shorthand for "use a search engine". There must be some
that are not flagged by your authorities.

You can also search at some of the 'mailing list as website' archives like
gmane.org, mail-archive.com, markmail.org, ...  At least the first two carry
(or carried) this list.

| registed " rcppmail at 163.com" in NetEase mailbox, then i use it to join the

Consider adding a .signature with your name and affiliation as is often
recommended on r-help and other R lists.  I show my name, so it seems fair to me to
ask the same from you.

| maillist. I used r-help maillist just several days ago. There must be a lot of
| things i don't know to use maillist like filter rule and the problem you said.
| but i will figure them out .

Sounds good. Always glad to help, but also trying not to answer the same
questions over and over -- I'd rather try answering new ones.

Have a look at the vignettes: Rcpp-introduction, Rcpp-FAQ, Rcpp-attributes as
well as the other ones depending on what you are interested in.

Dirk
 
 
 
 
| At 2014-08-05 08:50:02, "Dirk Eddelbuettel" <edd at debian.org> wrote:
| >
| >On 5 August 2014 at 17:30, super wrote:
| >|
| >| Yes , maybe that is very close to my needs , sorry for my pool english
| >| expression. But, the following code can't work:
| >| double meanC(NumericVector x) {
| >|    Function mean=Environment("package::base")["mean"];
| >|    return mean(x);
| >| }
| >| with the error "can't convert SEXP to double"
| >| How can i fix it ? Tks.
| >
| >With all due respect:
| >
| > i)    you have not motivated why you need mean from R
| >
| > ii)   how to call an R function from Rcpp as been discussed on this list
| >       probably half a dozen times by now, so please consider learning how to
| >       search the list archive via Google
| >
| > iii)  you are showing a somewhat larger amount of unfamiliarity with Rcpp
| >
| > iv)   you are hiding behind an anon mail handle in violation of the common
| >       R mailing list standards we follow here too
| >
| >so I am not going out of my way to repeat all of which you can already find
| >via ii) another time for you.
| >
| >Dirk
| >
| >
| >| At 2014-08-05 04:30:32, "Romain Francois" <romain at r-enthusiasts.com> wrote:
| >|
| >|     Not sure what you mean by hide the R function. You can extract a function
| >|     by its name on the C++ side :
| >|
| >|     Function bazinga("mean") ;
| >|
| >|     or extract it from a particular environment, e.g.
| >|
| >|     Environment("package:base")["mean"]
| >|
| >|     or
| >|
| >|     Environment base("package:base") ;
| >|     Function foo = base["mean"]
| >|
| >|     Romain
| >|
| >|     Le 5 août 2014 à 09:26, super <rcppmail at 163.com> a écrit :
| >|
| >|
| >|         Hello Rcppusers,
| >|           I want to call  a  r function in Cpp code, e.g.
| >|          int  meanC( NumericVector x) {
| >|             return mean(x,_["na.rm"]=TRUE);
| >|         }
| >|         Here function mean is a r function not rewrittened  Rcpp version's
| >|         mean. I do know one way to do this:
| >|          int  meanC( Function f,NumericVector x) {
| >|             return f(x,_["na.rm"]=TRUE);
| >|         }
| >|         Then  meanC(mean,1:3)
| >|         but can i hidden the true r function called ?  Is  r functions packed
| >|         into some namespace?
| >|
| >|
| >|
| >|
| >|         _______________________________________________
| >|         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
| >|
| >|
| >|
| >|
| >|
| >| _______________________________________________
| >| 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
| >
| >--
| >http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org
| 
| 
| 

-- 
http://dirk.eddelbuettel.com | @eddelbuettel | edd at debian.org


More information about the Rcpp-devel mailing list