In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
In this issue, the editor will bring you an example analysis of the Rcpp module supported by the cpp extension in R language. the article is rich in content and analyzes and describes it from a professional point of view. I hope you can get something after reading this article.
Overview
The Rcpp package provides C++ classes to facilitate C or C++ code to interact with the R software package using the .Call () calling interface provided in R. Rcpp provides C++ classes of the underlying data types in R for access. Package authors can maintain the data structure of R without constant conversion with C++. At the same time, these data structures provide C++-level access. Data types can be mapped in both directions. You can assign data from R to Candleships, and the returned data is exactly the same from C++ to R. The supported data types are listed below.
Transfer from R to Clearing, and from C++ to R
The R data type (SEXP) is consistent with the C++ object, according to the derivative relationship of the class. All R types are supported (vectors, functions, environment, etc...) And each pair corresponds to the class object of C++. For example, numeric vectors represents an instance of class Rcpp::NumericVector, environments represents Rcpp::Environment, functions represents Rcpp::Function, and so on. The corresponding C++ libraries provide the Rcpp::wrap function, which is a template function responsible for converting data into SEXP.
This mechanism makes it very straightforward to implement the logic of C++ using standard C++ types, such as programming with STL and returning it to R as SEXP. The internal encapsulation operation uses advanced metaprogramming technology. Currently supported data types include: bool, int, double, size_t, Rbyte, Rcomplex, std::string, STL containers (e.g std::vector) T encapsulable, STL maps (e.g std::map) T encapsulable, support implicit conversion of any type to SEXP. The reverse conversion (from R to C++) is done through the Rcpp::as function template.
New features
Starting with 0.7.1, the namespace Rcpp is provided. Contains the main class RObject, from which other classes are inherited, handling ENVSXP-related operations, "Language" language (LANGSXP) and template XPTr operation external pointers.
0.7.2 and subsequent versions extend these features to support automatic conversion of other R types and smarter use of templates.
0.8.1 added support uses modules to directly expose C++ code to R. The corresponding Rcpp-modules describes more details.
0.8.3 add sugar: expression template that allows compact vectorized expressions like those in R but implemented at compilation speed, see Rcpp-sugar for details.
0.8.6 Special function cherished for statistics: d/p/q/r-style for most relevant distribution, in a form that is very close to what we'd use in R.
0.8.7 adding ReferenceClasses supports in R 2.12.0; adding S4-based ReferenceClasses in the OO-style of Java or C++ to R language. 0.9.0 separate legacy classic API to RcppClassic.
0.10.0 brings Rcpp attributes, enhanced modules support and more.
0.11.0 brings simplified builds for packages using Rcpp, eliminating the need for link.
Inline use
0.7.0, Rcpp contains a modified 'cfunction', from the excellent' inline' package, which is developed by Oleg Sklyar. This allows users to define body of a C++ function like the standard R character vector-which is passed to 'cfunction' along with a few other parameters. The function then builds the complete C++ source file-and then compiles, links, and loads. This makes it very easy for Rcpp interface classes to implement R to C++-anyone can operate directly from the R prompt without the need for Makefiles, configuration settings, etc.
0.8.1, the extension function 'cxxfunction' is adopted (inline 0.3.5 is required). This function makes it easier to use C++ in Rcpp. Specifically, this forces the use of .call interface, plus the Rcpp namespace, and sets exception forwarding. Macros BEGIN_RCPP and END_RCPP were used to block user code.
What's more, through cfunction (and cxxfunction), we can even call external libraries and then linked.
Several examples are included in the package; one of them has been published to blog.
This can work on Windows if there is an'R tools' and R installation and it works. View R-on-Windows FAQ and other documents.
0.10.0, Rcpp attributes is complete, which is more powerful and easy to use than inline-check Rcpp attributes for details.
Unit testing
In version 0.11.5, more than 470 unit test functions called 928 unit tests to ensure API compatibility. Unit testing is also an applicable example. A vignette is auto-generated with the results of the unit tests.
Usage for package building
Rcpp provides the main header files Rcpp.h and library, in the lib of the installation package directory. In R, the directory location is calculated through system.file ("lib", "Rcpp.h", package= "Rcpp")-- but also provided through the function Rcpp::RcppCxxFlags () directory (). So you can call the form src/Makevars (or src/Makevars.win on Windows) like this
PKG_CXXFLAGS= `$ {R_HOME} / bin/Rscript-e "Rcpp:::CxxFlags ()" `PKG_LIBS= `${R_HOME} / bin/Rscript-e "Rcpp:::LdFlags ()"`
Check Rcpp-package for details. Also note that starting with version 0. 8. 0, the 'LinkingTo' parameter can be used in Rcpp packages. This allows R to determine the location of the header file, and the user only needs to use Rcpp::RcppLdFlags () (as detailed above) to point to the actual library
This is obviously a recommended method. In addition, we added a complete episode about how to use Rcpp in the package and discussed it in detail. Also note that the interlude of the RCPP attribute details another approach.
Rcpp manual
Book Seamless R and C++ integration with Rcpp (Spriger-2013) provides complete and complete documentation for Rcpp, as well as many examples. Here's more information. The book can be ordered directly from Springglass, Amazon and other booksellers.
Rcpp Gallery
The Rcpp gallery has reorganized more than 50 articles and examples for Rcpp. It is open to user contributions.
Demo package
The RcppExamples package (on CRAN) provides simple instructions on how to use Rcpp and can also be used as a framework for deploying Rcpp. However, this package is somewhat incomplete in terms of examples, so see the dozens of examples provided by packages that use Rcpp below.
Class documentation
We now have documentation for all the classes generated by Doxygen as apdf files in browsable and searchable htmland. We no longer include the Doxygen-generated document in the source tarball because it is too large. But we have zip archives of HTML, latex, and MAN documents.
The above is the analysis of the example that the cpp extension supports Rcpp module in R language shared by Xiaobian. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.