| Title: | 'Rcpp' Bindings for the 'fast_float' Header-Only Library for Number Parsing |
|---|---|
| Description: | Converting ascii text into (floating-point) numeric values is a very common problem. The 'fast_float' header-only C++ library by Daniel Lemire does it very well and very fast at up to or over to 1 gigabyte per second as described in more detail in <doi:10.1002/spe.2984>. 'fast_float' is licensed under the Apache 2.0 license and provided here for use by other R packages via a simple 'LinkingTo:' statement. |
| Authors: | Dirk Eddelbuettel [aut, cre] (ORCID: <https://orcid.org/0000-0001-6419-907X>), Brendan Knapp [aut] (ORCID: <https://orcid.org/0000-0003-3284-4972>), Daniel Lemire [aut] (ORCID: <https://orcid.org/0000-0003-3306-6922>) |
| Maintainer: | Dirk Eddelbuettel <[email protected]> |
| License: | GPL (>= 2) |
| Version: | 0.0.5 |
| Built: | 2026-05-19 06:07:28 UTC |
| Source: | https://github.com/eddelbuettel/rcppfastfloat |
double ConversionFor character vectors, as.double2() is a
drop-in replacement for base::as.double().
as.double2(x)as.double2(x)
x |
A vector of type |
as.double()
set.seed(8675309) input <- sample(c( paste0(" \r\n\t\f\v", c(0.0, sqrt(seq(1, 10))), " \r\n\t\f\v"), c("NaN", "-NaN", "nan", "-nan", "Inf", "-Inf", "inf", "-inf", "infinity", "-infinity", NA_character_, " 1970-01-01", "1970-01-02 ") )) input suppressWarnings(as.double2(input)) # NAs introduced by coercion comparison <- suppressWarnings( matrix(c(as.double(input), as.double2(input)), ncol = 2L, dimnames = list(NULL, c("as.double()", "as.double2()"))) ) comparison all.equal(comparison[, "as.double()"], comparison[, "as.double2()"])set.seed(8675309) input <- sample(c( paste0(" \r\n\t\f\v", c(0.0, sqrt(seq(1, 10))), " \r\n\t\f\v"), c("NaN", "-NaN", "nan", "-nan", "Inf", "-Inf", "inf", "-inf", "infinity", "-infinity", NA_character_, " 1970-01-01", "1970-01-02 ") )) input suppressWarnings(as.double2(input)) # NAs introduced by coercion comparison <- suppressWarnings( matrix(c(as.double(input), as.double2(input)), ncol = 2L, dimnames = list(NULL, c("as.double()", "as.double2()"))) ) comparison all.equal(comparison[, "as.double()"], comparison[, "as.double2()"])
This example is adapted from the example of the upstream README.md file, and generalized to be called from R with variable input.
parseExample(input = "3.1416 xyz ", verbose = TRUE)parseExample(input = "3.1416 xyz ", verbose = TRUE)
input |
A character variable with text to parse including a simple default |
verbose |
A boolean variable to show or suppress progress, defaults to true |
A floating point scalar is returned on success; in case of parsing failure
the function exists via stop().
parseExample()parseExample()