0

Using the package R::extraDistr I noticed that many R functions of this package just call some cpp functions that do exactly the same work. For example, writing the command dtnorm, that gives us the density function of the truncated Normal distribution, we obtain in console

function (x, mean = 0, sd = 1, a = -Inf, b = Inf, log = FALSE) 
{
   cpp_dtnorm(x, mean, sd, a, b, log[1L])
}
<environment: namespace:extraDistr>

and so it seems that the R function just calls the respective c++ version, that is called cpp_dtnorm.

Since I'm writing the C++ and I need to use some of the functions included in this package, are there some ways to call directly the cpp_ functions without passing through the "R versions"?

Maybe it should be sufficient to find the script with the cpp_ function in the package directory, copy the code of interest and paste it into my script, but actually I do not know where I can find it. Can you help me in some ways?

Thank you all.

  • 1
    https://github.com/cran/extraDistr/blob/master/src/truncated-normal-distribution.cpp – Martin Schmelzer Nov 24 '17 at 13:55
  • Is [this SO question](https://stackoverflow.com/questions/20474303/using-c-function-from-other-package-in-rcpp) or [this chapter from Hadley Wickham's R Packages](http://r-pkgs.had.co.nz/src.html#cpp) -- specifically the "Importing C++ code" subsection -- helpful? – duckmayr Nov 24 '17 at 13:58
  • 1
    Not unless the other package exports it. This really is a duplicate. – Dirk Eddelbuettel Nov 24 '17 at 14:09
  • @MartinSchmelzer I found your link very useful and it is exactly what I'm searching for. However, trying to compile the code I noticed that the file "shared.h" doesn't exist. How to deal with this? Thank you – Andrea Sottosanti Nov 24 '17 at 15:30
  • The file is found in the repository as well. – Martin Schmelzer Nov 24 '17 at 15:32

0 Answers0