-
Notifications
You must be signed in to change notification settings - Fork 76
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
Export errors unnecessarily if passed x is a list of length one. #385
Comments
I haven't tested this, but I think it can be done in export.R by replacing if (!is.data.frame(x) && !format %in% c("xlsx", "html", "rdata", "rds", "json", "qs", "fods", "ods")) { with if (!is.data.frame(x) && !format %in% c("xlsx", "html", "rdata", "rds", "json", "qs", "fods", "ods")) { |
@cha-petersumm Thank you for reporting and suggesting a solution. There will be an update. But I will put if (is.list(x) && (length(x) == 1) && is.data.frame(x[[1]])) {
x <- x[[1]]
} in an outer loop. |
No problem. You want to avoid doing this for file formats where it's not necessary. In particular, for Excel files, exporting a list preserves the sheet names whereas converting a list of length = 1 to the first element and then exporting will lose them. |
Please install the latest version install.packages("rio", repos = "https://gesistsa.r-universe.dev") And there are tests for preserving sheet names when |
Great work! Thanks. |
Also, in case it's ever useful to you, this is my example of where it was used. It's written to de-identify files containing patient data: cat(---
|
It would be neater if the export function worked when passed a dataframe list with length = 1, regardless of the export format.
An error would still occur if length > 1 and the export format didn't support it.
This would avoid the need for this sort of code:
if (length(data_list) > 1 | info$export_function == "writexl::write_xlsx")
export(data_list, output_filename)
else
export(data_list[[1]], output_filename)
The text was updated successfully, but these errors were encountered: