New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overpermissive parsing of strings #221

Closed
rgayler opened this Issue Jul 21, 2015 · 1 comment

Comments

Projects
None yet
2 participants
@rgayler

rgayler commented Jul 21, 2015

# 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)
@hadley

This comment has been minimized.

Member

hadley commented Sep 3, 2015

Minimal reprex

parse_numeric("3d")
parse_double("3d")
parse_integer("3d")

I believe the behaviour of parse_numeric() is correct (and as documented), but parse_double() and parse_integer() should return NA, not 3.

@hadley hadley closed this in db939bc Sep 3, 2015

@lock lock bot locked and limited conversation to collaborators Sep 25, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.