-
Notifications
You must be signed in to change notification settings - Fork 286
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
Add support for show_col_types for edition 1 parser #1332
Changes from all commits
f25787c
bf256d1
25b832c
0e0b64f
1b12731
e592c7d
cec9413
63a2da4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,12 +27,22 @@ show_progress <- function() { | |
|
||
#' Determine whether column types should be shown | ||
#' | ||
#' Column types are shown unless | ||
#' - They are disabled by setting `options(readr.show_col_types = FALSE)` | ||
#' - The column types are supplied with the `col_types` argument. | ||
#' Wrapper around `getOption("readr.show_col_types")` that implements some fall | ||
#' back logic if the option is unset. This returns: | ||
#' * `TRUE` if the option is set to `TRUE` | ||
#' * `FALSE` if the option is set to `FALSE` | ||
#' * `FALSE` if the option is unset and we appear to be running tests | ||
#' * `NULL` otherwise, in which case the caller determines whether to show | ||
#' column types based on context, e.g. whether `show_col_types` or actual | ||
#' `col_types` were explicitly specified | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I reworded this to focus more closely on what this helper does. I still include some words about downstream use, in the |
||
#' @export | ||
should_show_types <- function() { | ||
if (identical(getOption("readr.show_col_types", TRUE), FALSE)) { | ||
opt <- getOption("readr.show_col_types", NA) | ||
if (isTRUE(opt)) { | ||
TRUE | ||
Comment on lines
+41
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is new. But this just feels more natural and expected to me that if the option is |
||
} else if (identical(opt, FALSE)) { | ||
FALSE | ||
} else if (is.na(opt) && is_testing()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved the |
||
FALSE | ||
} else { | ||
NULL | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# options(readr.show_col_spec) controls column specifications | ||
|
||
Code | ||
out <- read_csv(readr_example("mtcars.csv")) | ||
Message <readr_spec_message> | ||
|
||
-- Column specification -------------------------------------------------------- | ||
cols( | ||
mpg = col_double(), | ||
cyl = col_double(), | ||
disp = col_double(), | ||
hp = col_double(), | ||
drat = col_double(), | ||
wt = col_double(), | ||
qsec = col_double(), | ||
vs = col_double(), | ||
am = col_double(), | ||
gear = col_double(), | ||
carb = col_double() | ||
) | ||
|
||
# `show_col_types` controls column specification | ||
|
||
Code | ||
out <- read_csv(readr_example("mtcars.csv"), show_col_types = TRUE) | ||
Message <readr_spec_message> | ||
|
||
-- Column specification -------------------------------------------------------- | ||
cols( | ||
mpg = col_double(), | ||
cyl = col_double(), | ||
disp = col_double(), | ||
hp = col_double(), | ||
drat = col_double(), | ||
wt = col_double(), | ||
qsec = col_double(), | ||
vs = col_double(), | ||
am = col_double(), | ||
gear = col_double(), | ||
carb = col_double() | ||
) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# options(readr.show_col_spec) controls column specifications | ||
|
||
Code | ||
out <- read_csv(readr_example("mtcars.csv")) | ||
Message <vroom_dim_message> | ||
Rows: 32 Columns: 11 | ||
Message <vroom_spec_message> | ||
-- Column specification -------------------------------------------------------- | ||
Delimiter: "," | ||
dbl (11): mpg, cyl, disp, hp, drat, wt, qsec, vs, am, gear, carb | ||
|
||
i Use `spec()` to retrieve the full column specification for this data. | ||
i Specify the column types or set `show_col_types = FALSE` to quiet this message. | ||
|
||
# `show_col_types` controls column specification | ||
|
||
Code | ||
out <- read_csv(readr_example("mtcars.csv"), show_col_types = TRUE) | ||
Message <vroom_dim_message> | ||
Rows: 32 Columns: 11 | ||
Message <vroom_spec_message> | ||
-- Column specification -------------------------------------------------------- | ||
Delimiter: "," | ||
dbl (11): mpg, cyl, disp, hp, drat, wt, qsec, vs, am, gear, carb | ||
|
||
i Use `spec()` to retrieve the full column specification for this data. | ||
i Specify the column types or set `show_col_types = FALSE` to quiet this message. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
pre_test_options <- options( | ||
readr.show_col_types = FALSE, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer to leave this unset and let |
||
readr.show_progress = FALSE | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved the
is_testing()
matter intoshould_show_types()
.