Currently use_template throws an error when one chooses not to overwrite an existing file:
usethis::use_template(template = "CONTRIBUTING.md")
Overwrite pre-existing file 'CONTRIBUTING.md'?
3: Not now
Error: 'CONTRIBUTING.md' already exists.
Is there any appetite for a PR that would add a allow_existing argument (or whatever the name) to use_template? So that is, if a file already exists and the allow_existing argument is set to TRUE, and a user selects to not overwrite (at the prompt), use_template simply outputs a 'CONTRIBUTING.md' already exists' warning rather than an error?
I agree it makes sense to be able to opt-out of overwrite and not throw an error. However, my mind is very much elsewhere right now.
Before making a PR, will you give a few bullet points re: what you plan to do so @hadley can also give a quick 👍?
The objective is to make sure the change really needs to happen in usethis vs. in your package (without forcing you to do some awkward tryCatch() thing). Let's make sure the accommodations are made in the most sensible place(s).
I don't see why this needs to stop() if interactive(), i.e. a human was presented with and made a choice. I propose you make a PR with no new argument. If !can_overwrite() and interactive() then warn or message and return FALSE from write_over().
…e an existing file and instead produces a message (#350)
* a negative user response to overwriting a file produces a message instead of an error. Closes#348
* only modify if open = TRUE and the file is actually created
* modify test_that names to reflect warnings
* use longer form comparison
* skip R 3.1 when testing message for use_readme overwrite
* Tweak docs
Also a test to see if I can push to boshek/master
* Swap an if-else
* These functions have moved
* Use `done()` instead of `message()`
* Add expectations for file or dir in the project
* Finish adjusting to new behaviour or write_over() and use_template()
use_templatethrows an error when one chooses not to overwrite an existing file:
Is there any appetite for a PR that would add a
allow_existingargument (or whatever the name) to
use_template? So that is, if a file already exists and the
allow_existingargument is set to
TRUE, and a user selects to not overwrite (at the prompt),
use_templatesimply outputs a 'CONTRIBUTING.md' already exists' warning rather than an error?
The context is that we have a series of templates (CoC, README, etc) where a user, when setting up a project or package, may accept the template for some and keep existing files for others. Since
write_overthrows an error, this type of process where sequential asking which files need to be overwritten is currently not possible.
The text was updated successfully, but these errors were encountered: