CppVector | A ShiViz-compatible logging library for C
kandi X-RAY | CppVector Summary
kandi X-RAY | CppVector Summary
A ShiViz-compatible logging library for C++
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of CppVector
CppVector Key Features
CppVector Examples and Code Snippets
Community Discussions
Trending Discussions on CppVector
QUESTION
Is there a base function in Rcpp that:
- Fills entirely by a single value if size of a vector is 1.
- Fills the other vector completely if same length.
- Fills with an
NA
value if neither Vector are the same length nor a vector is of size 1.
I've written the above criteria as a function below using a NumericVector
as an example. If there isn't a base function in Rcpp that performs said operations there should be a way to template the function so that given any type of vector (e.g. numeric
, character
and so on) the above logic would be able to be executed.
ANSWER
Answered 2017-Apr-13 at 15:14Unfortunately, the closest you will come to such a function is one of the rep
variants that Rcpp supports. However, none of the variants match the desired output. Therefore, the only option is to really implement a templated version of your desired function.
To create the templated function, we will first create a routing function that handles the dispatch of SEXP
objects. The rationale behind the routing function is SEXP
objects are able to be retrieved from and surfaced into R using Rcpp Attributes whereas a templated version is not. As a result, we need to specify the SEXTYPE (used as RTYPE) dispatches that are possible. The TYPEOF()
macro retrieves the coded number. Using a switch
statement, we can dispatch this number into the appropriate cases.
After dispatching, we arrive at the templated function. The templated function makes use of the base Vector
class of Rcpp to simplify the data flow. From here, the notable novelty will be the use of ::traits::get_na()
to dynamically retrieve the appropriate NA
value and fill it.
With the plan in place, let's look at the code:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install CppVector
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page