Learn R Programming

Numero (version 1.8.4)

nroRcppVector: Safety check for Rcpp calls

Description

Ensures vectors can be passed safely to C++ functions.

Usage

nroRcppVector(data, default, numeric = TRUE, empty = TRUE)

Arguments

data

A vector.

default

Default output if input is empty.

numeric

If TRUE, output is converted into a numeric vector, otherwise a character vector is returned.

empty

If TRUE, empty output is allowed.

Value

A numeric or a character vector.

Details

Checks the input for size (0 is allowed if empty flag is set) and that it is a vector (or can be converted to a vector).

Examples

Run this code
# NOT RUN {
# Empty input reverts to default.
x <- nroRcppVector(data=NULL, default=NA, empty=TRUE)
print(x)

# Empty input reverts to default, then to specified type.
x <- nroRcppVector(data=NULL, default=123, empty=TRUE, numeric=FALSE)
print(x)

# Convert a logical vector to numbers.
x <- c(TRUE, TRUE, FALSE, TRUE)
names(x) <- c("a","b","c","d")
y <- nroRcppVector(data=x, numeric=TRUE)
print(y)
# }

Run the code above in your browser using DataLab