-
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
More helpful error when trying to write out data frames with list columns #1009
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.
Implementation looks great - I added a few comments about style.
R/write.R
Outdated
format(x, "%Y-%m-%dT%H:%M:%OSZ", tz = "UTC", justify = "none") | ||
} | ||
|
||
#' @export | ||
output_column.list <- function(x, name) { | ||
stop(paste0("Flat files can't store the list column '", name, "'")) |
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 think this should use `
rather than '
, and you need a call. = FALSE
on the end. Also stop()
automatically pastes together it's inputs, you can remove the paste()
if you want.
tests/testthat/test-write.R
Outdated
@@ -163,3 +163,11 @@ test_that("hms NAs are written without padding (#930)", { | |||
df <- data.frame(x = hms::as.hms(c(NA, 34.234))) | |||
expect_equal(format_tsv(df), "x\nNA\n00:00:34.234\n") | |||
}) | |||
|
|||
test_that("More helpful error when trying to write out data frames with list columns (#938)", { | |||
df <- tibble::tibble(id = seq(11)) |
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'd make this a little simpler: df <- tibble(x = 1, y = list(1))
tests/testthat/test-write.R
Outdated
df$list <- lapply(X = seq_along(df$id), FUN = rnorm, n = 3) | ||
filename <- file.path(tempdir(), "test_list.csv") | ||
on.exit(unlink(filename)) | ||
expect_error(write_csv(x = df, path = filename), "Flat files can't store the list column '") |
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'd just do write_csv(df, tempfile())
— you don't need to clean up since this won't read a file.
Thanks @hadley, I push some new changes following your suggestions! |
Thanks @ellessenne |
Because of the way #1009 was implemented it caused a bug when writing data with duplicated column names. It also only preformed the check for `write_delim()`, not for all the writing functions. We now do this in a different way, which again restores the ability to write data with duplicated columns. Fixes #1169
Closes #938:
However, this approach does not work so well when multiple list columns are present:
Is this behaviour acceptable or would it be better to print the names of all unsupported list columns at once?
Alessandro