Learn R Programming

jwutil (version 1.2.3)

fastIntToString: Fast convert integer vector to character vector

Description

Fast conversion from integer vector to character vector using C++

Usage

fastIntToStringStd(x)

Arguments

x

vector of integers

bufferSize

int if any input strings are longer than this number (default 16) there will be memory errors. No checks done for speed.

Examples

Run this code
# NOT RUN {
pts <- generate_random_pts(1e7)
# conclusion: buffer size matters little (so default to be more generous),
# and Rcpp version fastest.
microbenchmark::microbenchmark(fastIntToStringStd(pts$visit_id, buffer = 8),
                               fastIntToStringStd(pts$visit_id, buffer = 16),
                               fastIntToStringStd(pts$visit_id, buffer = 64),
                               fastIntToStringRcpp(pts$visit_id, buffer = 8),
                               fastIntToStringRcpp(pts$visit_id, buffer = 16),
                               fastIntToStringRcpp(pts$visit_id, buffer = 64),
                               as.character(pts$visit_id),
                               as_char_no_warn(pts$visit_id), times = 5)
# }

Run the code above in your browser using DataLab