Skip to content

Overpermissive parsing of strings #221

@rgayler

Description

@rgayler
# BUG - [parse|col]_double not consistent with *_numeric and *_integer
# *_double("information") -> Inf
# whereas *_numeric("information) -> NA and *_integer("information") -> NA

# DESIGN - Having *_[numeric|double|integer]("3D graphics) - > 3
# May be convenient but strikes me as dangerous.
# How about including a parameter "strict = TRUE | FALSE"
# strict = FALSE gives the current behaviour 
# strict = TRUE gives NA if there are any problems
# I would argue for strict = TRUE as the default

library(readr) # V 0.1.1 from CRAN

# make an input text
in_stream <- "information\n3d graphics"
in_vec <- c("information", "3d graphics")

# parse it different ways
xpn <- parse_numeric(in_vec) # 1 problem
xpd <- parse_double(in_vec)  # 2 problems
xpf <- parse_float(in_vec)  # no such function
xpi <- parse_integer(in_vec) # 2 problems

# collect it different ways
xcn <- read_csv(in_stream, col_names = FALSE, col_types = list(col_numeric())) # 1 problem
xcd <- read_csv(in_stream, col_names = FALSE, col_types = list(col_double()))  # 2 problems
xcf <- read_csv(in_stream, col_names = FALSE, col_types = list(col_float()))  # no such function
xci <- read_csv(in_stream, col_names = FALSE, col_types = list(col_integer())) # 2 problems

xpn
xcn
problems(xcn)

xpd
xcd
problems(xcd)

xpi
xci
problems(xci)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions