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.48550/arXiv2101.11408>. '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, Brendan Knapp |
Maintainer: | Dirk Eddelbuettel <[email protected]> |
License: | GPL (>= 2) |
Version: | 0.0.4 |
Built: | 2024-09-04 05:21:43 UTC |
Source: | https://github.com/eddelbuettel/rcppfastfloat |
double
ConversionFor character
vector
s, 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()