R/utils.r

Defines functions parse_float

Documented in parse_float

#' Parse an XMLNode into a float by stripping everything non-numeric
#' around the first numeric.
#' @param value XMLNode or character.
#' @return numeric that represents the parsed value.
parse_float <- function(value) {
  if (inherits(value, 'XMLInternalNode')) value <- xmlValue(value)
  as.numeric(gsub('[^0-9.].*$', '', gsub('^[^0-9.]*', '', value)))
}
robertzk/amazonreviews documentation built on May 27, 2019, 10:34 a.m.