-
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 new whitespace-delimited example file and update examples for read_table()
and melt_*()
#1354
Conversation
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 made a few inline comments.
I recommend updating any melt_*()
function to wherever this ends up. Yeah those functions are slated to live elsewhere, but it's also not too hard to make sure the example code is sensible in the meantime.
I prefer writeLines(read_lines(...))
over cat(read_lines(...))
. This is already used in some places.
Nudge me to help make sense of the snapshot test failure. We'll probably want to resolve that first, in |
R/melt_table.R
Outdated
#' ws <- readr_example("whitespace-sample.txt") | ||
#' writeLines(read_file(ws)) | ||
#' melt_table(ws) |
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.
#' ws <- readr_example("whitespace-sample.txt") | |
#' writeLines(read_file(ws)) | |
#' melt_table(ws) | |
#' fwf <- readr_example("fwf-sample.txt") | |
#' writeLines(read_lines(fwf)) | |
#' melt_table(fwf) | |
#' | |
#' ws <- readr_example("whitespace-sample.txt") | |
#' writeLines(read_lines(ws)) | |
#' melt_table2(ws) |
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.
Remember the overall goal is to demonstrate readr functions with an example dataset that shows the most suitable input for the function. The discovery of #1333 is that these examples were originally written when readr behaved differently. Then the readr functions changed, but the examples didn't, which left behind some rather nonsensical example code.
The melt*()
functions are designed to return output where "each row represents a single token".
I think melt_table()
is best paired with fwf-sample.txt
. melt_table2()
makes much more sense for whitespace-sample.txt
.
Also, from playing around with this, I think read_lines()
is generally what we want (not read_file()
).
library(readr)
fwf <- readr_example("fwf-sample.txt")
writeLines(read_lines(fwf))
#> John Smith WA 418-Y11-4111
#> Mary Hartford CA 319-Z19-4341
#> Evan Nolan IL 219-532-c301
melt_table(fwf)
#> Warning: `melt_table()` was deprecated in readr 2.0.0.
#> Please use `meltr::melt_table()` instead
#> # A tibble: 12 × 4
#> row col data_type value
#> <dbl> <dbl> <chr> <chr>
#> 1 1 1 character John
#> 2 1 2 character Smith
#> 3 1 3 character WA
#> 4 1 4 character 418-Y11-4111
#> 5 2 1 character Mary
#> 6 2 2 character Hartford
#> 7 2 3 character CA
#> 8 2 4 character 319-Z19-4341
#> 9 3 1 character Evan
#> 10 3 2 character Nolan
#> 11 3 3 character IL
#> 12 3 4 character 219-532-c301
ws <- readr_example("whitespace-sample.txt")
writeLines(read_lines(ws))
#> first last state phone
#> John Smith WA 418-Y11-4111
#> Mary Hartford CA 319-Z19-4341
#> Evan Nolan IL 219-532-c301
# this doesn't make much sense as an example
# it does not produce one token per row
melt_table(ws)
#> Warning: `melt_table()` was deprecated in readr 2.0.0.
#> Please use `meltr::melt_table()` instead
#> # A tibble: 4 × 4
#> row col data_type value
#> <dbl> <dbl> <chr> <chr>
#> 1 1 1 character first last state phone
#> 2 2 1 character John Smith WA 418-Y11-4111
#> 3 3 1 character Mary Hartford CA 319-Z19-4341
#> 4 4 1 character Evan Nolan IL 219-532-c301
# this does
melt_table2(ws)
#> Warning: `melt_table2()` was deprecated in readr 2.0.0.
#> Please use `meltr::melt_table2()` instead
#> # A tibble: 16 × 4
#> row col data_type value
#> <dbl> <dbl> <chr> <chr>
#> 1 1 1 character first
#> 2 1 2 character last
#> 3 1 3 character state
#> 4 1 4 character phone
#> 5 2 1 character John
#> 6 2 2 character Smith
#> 7 2 3 character WA
#> 8 2 4 character 418-Y11-4111
#> 9 3 1 character Mary
#> 10 3 2 character Hartford
#> 11 3 3 character CA
#> 12 3 4 character 319-Z19-4341
#> 13 4 1 character Evan
#> 14 4 2 character Nolan
#> 15 4 3 character IL
#> 16 4 4 character 219-532-c301
Created on 2022-01-24 by the reprex package (v2.0.1.9000)
1ad3c59
to
79e1cd4
Compare
read_table()
and melt_*()
Closes #1333