You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow user to decline to overwrite existing file, from use_template() #348
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'?
1: Absolutely
2: No
3: Not now
Selection: 3
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?
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 use_template via write_over throws an error, this type of process where sequential asking which files need to be overwritten is currently not possible.
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().
changed the title [-]Feature request - argument to allow use_template warning on existing files[/-][+]Allow user to decline to overwrite existing file, from use_template()[/+]on Aug 12, 2018
Activity
jennybc commentedon May 11, 2018
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).boshek commentedon May 11, 2018
Definitely where I am at right now
Ok here is a shot at what I would try:
write_overhere:allow_existingargument towrite_overanduse_templateallow_existingforuse_templatejennybc commentedon May 12, 2018
I don't see why this needs to
stop()ifinteractive(), i.e. a human was presented with and made a choice. I propose you make a PR with no new argument. If!can_overwrite()andinteractive()then warn or message and returnFALSEfromwrite_over().a negative user response to overwriting a file produces a message ins…
[-]Feature request - argument to allow use_template warning on existing files[/-][+]Allow user to decline to overwrite existing file, from use_template()[/+]`use_template()` no longer errors when a user chooses not to overwrit…