Skip to content
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

Reconsider the addition of overwrite = FALSE argument to write.xlsx #249

Closed
jeromyanglim opened this issue Aug 25, 2021 · 3 comments
Closed

Comments

@jeromyanglim
Copy link

I've recently upgraded openxlsx (i.e., version 4.2.4).
The function write.xlsx now appears to have a default argument overwrite = FALSE.
This appears to be new. I don't upgrade all that often, so my apologies if it's been around for quite a while.

I think this default is undesirable for several reasons:

  • It is inconsistent with other data.frame saving functions in R. e.g., write.csv, write.table. In fact, just about any function that allows you to save a file in R allows you save that file over the top of an existing file.
  • It breaks a lot of old code that assumed that it is fine to save an excel file on top of a file.
  • It's a more common use case to be updating a file with new output than to be worried about deleting an existing file.
  • It also leads to surprising results for reproducible analyses. I.e., the first time you run your code, you get no errors, because the excel output file does not exist yet. Then you run your code a second time and you get an error (i.e., File already exists), because the file now exists. So you have to work out what is going on and then fix the error by adding the text overwrite = TRUE to the function call. This is surprising behaviour and adds to the verbosity and mental load of using the function.

A typical example of me using write.xlsx would be where I have generated some results, and I'm saving these to a folder.
If I re-run the analyses, I'll save the latest results over the top.
In general, I think you can think of R users as mature enough to know that files generated by R (e.g., using tools like write.xlsx) should not be edited in place.

So, I think the best solution would be to make the default overwrite = TRUE again especially for write.xlsx.

@JanMarvin
Copy link
Collaborator

Hi @jeromyanglim , I'm in favor of changing the default, though it leaves the potential problem, that the onus will be on the others who rely on the current behavior. What do you think @ycphs ?

@jmbarbone
Copy link
Contributor

I'd be favor of the default of FALSE. This is passed down to file.copy() where the default value for overwrite will be FALSE (unless recursive is TRUE). This was also passed intermediated to saveWorkbook() where the default value is FALSE. Since write.xlsx() is just a wrapper for creating and saving the workbook, to me it makes sense to keep the default values of the parameters consistent. I don't see it necessarily as a large burden.

However, I'm fairly certain this change was introduced unintentionally. There are no notes about it in the NEWS and the documentation for write.xlsx() is inconsistent: the argument is listed as a default of FALSE but the details indicates that the default is TRUE. For those reasons I think it's better to revert back.

@tylerlittlefield
Copy link

The default of FALSE has caused quite a bit of headaches for me. Really happy to see it has been reverted on the development version! 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants