Guillermo.Vinue at uv.es
2013-Jun-06 13:54 UTC
[Rd] Question about writing portable packages
Dear R-devel list, I am creating an R package that includes C++ code. I tried to install it both in Linux and Windows and it worked. I load the C code via the NAMESPACE file using useDynLib. Now I am revising once again whether everything is ready before submitting the package to CRAN and I have read in http://cran.r-project.org/doc/manuals/R-exts.html#Writing-portable-packages that ?It is not portable to call compiled code in R or other packages via .Internal, .C, .Fortran, .Call or .External, since such interfaces are subject to change without notice and will probably result in your code terminating the R process?. However, the R function of my package that calls the C++ code uses the Call function. Does it mean that I cannot submit my package to CRAN because the portability is not guaranteed?. Then, how could I to call C++ code so that my package were portable?. I hope you can clarify my doubts. I have seen the collection of prior postings to the list, but I have not found a specifical answer to my doubts . Thank you very much in advance. Best regards, Guillermo
I think the key word here is _other_ packages. It's entirely okay to call your package's own compiled code through the .Call interface (and the code you write may link to other packages; the obvious example being Rcpp code you write); however, it is not portable to use .Call to call compiled code from another package directly. This is because package authors are not required to maintain a consistent .Call interface to their compiled code; rather, they just have to make sure the direct user-facing R exported functions retain a stable interface over different versions (or, if changed, are done so with prior warning etc.) Ultimately, if your package passes 'R CMD check' with no errors, warnings or notes, you should be okay for CRAN submission. -Kevin On Thu, Jun 6, 2013 at 6:54 AM, <Guillermo.Vinue@uv.es> wrote:> Dear R-devel list, > > I am creating an R package that includes C++ code. I tried to install it > both in Linux and Windows and it worked. I load the C code via the > NAMESPACE file using useDynLib. > > Now I am revising once again whether everything is ready before > submitting the package to CRAN and I have read in > http://cran.r-project.org/doc/manuals/R-exts.html#Writing-portable-packages > that “It is not portable to call compiled code in R or other packages > via .Internal, .C, .Fortran, .Call or .External, since such interfaces > are subject to change without notice and will probably result in your > code terminating the R process”. > > However, the R function of my package that calls the C++ code uses the > Call function. > > Does it mean that I cannot submit my package to CRAN because the > portability is not guaranteed?. Then, how could I to call C++ code so > that my package were portable?. > > I hope you can clarify my doubts. I have seen the collection of prior > postings to the list, but I have not found a specifical answer to my > doubts . > > Thank you very much in advance. > > Best regards, > > Guillermo > > ______________________________________________ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- -Kevin [[alternative HTML version deleted]]
Guillermo, That phrase is referring to using .Call in your package to call a C function that shipped with a DIFFERENT package or is part of R itself (defined in the R source code). As long as you are only calling C functions you define in the C++ code that ships with your package you are fine. ~G On Thu, Jun 6, 2013 at 6:54 AM, <Guillermo.Vinue@uv.es> wrote:> Dear R-devel list, > > I am creating an R package that includes C++ code. I tried to install it > both in Linux and Windows and it worked. I load the C code via the > NAMESPACE file using useDynLib. > > Now I am revising once again whether everything is ready before > submitting the package to CRAN and I have read in > http://cran.r-project.org/doc/manuals/R-exts.html#Writing-portable-packages > that “It is not portable to call compiled code in R or other packages > via .Internal, .C, .Fortran, .Call or .External, since such interfaces > are subject to change without notice and will probably result in your > code terminating the R process”. > > However, the R function of my package that calls the C++ code uses the > Call function. > > Does it mean that I cannot submit my package to CRAN because the > portability is not guaranteed?. Then, how could I to call C++ code so > that my package were portable?. > > I hope you can clarify my doubts. I have seen the collection of prior > postings to the list, but I have not found a specifical answer to my > doubts . > > Thank you very much in advance. > > Best regards, > > Guillermo > > ______________________________________________ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >-- Gabriel Becker Graduate Student Statistics Department University of California, Davis [[alternative HTML version deleted]]