feat: add replace arg to use_external_* wrappers#1247
Merged
Conversation
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR adds a replace = FALSE option across the use_external_* file helpers (and use_bundled_html()) to allow overwriting existing target files/directories, and updates shared tooling + tests/docs accordingly.
Changes:
- Add
replaceparameter touse_external_js_file(),use_external_css_file(),use_external_html_template(),use_external_file(), anduse_bundled_html(), and plumb it through download/check helpers. - Update
check_file_exists()to short-circuit whenreplace = TRUEand enhance the “already exists” message. - Add tests for replace behavior in the external wrappers and
check_file_exists(), plus update NEWS + dev version.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
R/use_files_external.R |
Adds replace arg to exported external helpers; implements bundle cleanup when replacing. |
R/use_files_external_tools.R |
Threads replace through the shared “checks + download” helper. |
R/use_files_shared_tools.R |
Extends check_file_exists() with replace support and updated abort message. |
tests/testthat/test-use_files.R |
Adds coverage for default-abort vs replace = TRUE across use_external_* wrappers. |
tests/testthat/test-use_files_shared_tools.R |
Adds coverage for check_file_exists(replace = TRUE) no-op behavior. |
man/use_files.Rd |
Documents the new replace parameter in the public API docs. |
NEWS.md |
Adds a development NEWS entry describing the new replace option. |
DESCRIPTION |
Bumps package version to 0.6.0.9000. |
Files not reviewed (1)
- man/use_files.Rd: Language not supported
Comments suppressed due to low confidence (1)
R/use_files_shared_tools.R:66
check_file_exists()is used by multiple helpers (e.g., internal file copy/add flows) that don’t expose areplaceargument, but the abort text now tells users to “call this function again withreplace = TRUE”. That makes the error message misleading in those contexts. Consider moving thereplacehint to the specific public functions that support it, or wording it conditionally (e.g., “if supported by the calling function”).
cli_abort(
sprintf(
"%s already exists.\n\nYou can delete it with:\nunlink('%s', recursive = TRUE).\n\nAlternatively, call this function again with `replace = TRUE`.",
where,
where
)
)
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Move `replace` to the end of the signature in `use_external_*` and `use_bundled_html()` to preserve positional-arg backward compatibility with `dir_create`/`pkg`/`extract`/`delete_zip`. - Clarify the `@param replace` doc to mention "file or directory" since `use_bundled_html()` can also replace a bundle directory. - `check_file_exists()` gains a `with_replace_hint = FALSE` arg so the "call with `replace = TRUE`" hint only appears for callers that actually expose `replace` (avoids misleading errors from internal helpers like `add_files.R` and `use_files_internal_tools.R`). - Add a test covering `use_bundled_html(replace = TRUE)` cleanup for both an existing bundle directory and a stale file at the same path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #819.
Summary
replace = FALSEargument touse_external_js_file(),use_external_css_file(),use_external_html_template(),use_external_file()anduse_bundled_html(). WhenTRUE, anexisting file at the target location is overwritten instead of
aborting.
use_bundled_html(), the extracted bundle directory (and anystale file at the same path) is also removed before re-extraction
when
replace = TRUE—unzip()does not clean it on its own.check_file_exists()gains areplaceshort-circuit and the abortmessage now mentions the option.
0.6.0.9000.NEWS.md
New features
Test plan
devtools::test()— 625 PASS, 0 FAIL.replace = TRUEpaths forthe 4
use_external_*functions.check_file_exists(replace = TRUE).🤖 Generated with Claude Code