Skip to content

feat: add replace arg to use_external_* wrappers#1247

Merged
ColinFay merged 3 commits into
masterfrom
add-replace-use-external
May 18, 2026
Merged

feat: add replace arg to use_external_* wrappers#1247
ColinFay merged 3 commits into
masterfrom
add-replace-use-external

Conversation

@ColinFay
Copy link
Copy Markdown
Member

Closes #819.

Summary

  • Add a replace = FALSE argument to use_external_js_file(),
    use_external_css_file(), use_external_html_template(),
    use_external_file() and use_bundled_html(). When TRUE, an
    existing file at the target location is overwritten instead of
    aborting.
  • For use_bundled_html(), the extracted bundle directory (and any
    stale file at the same path) is also removed before re-extraction
    when replace = TRUEunzip() does not clean it on its own.
  • check_file_exists() gains a replace short-circuit and the abort
    message now mentions the option.
  • Bump dev version to 0.6.0.9000.

NEWS.md

New features

Test plan

  • devtools::test() — 625 PASS, 0 FAIL.
  • New test covers the default-abort and replace = TRUE paths for
    the 4 use_external_* functions.
  • New test covers check_file_exists(replace = TRUE).

🤖 Generated with Claude Code

ColinFay and others added 2 commits May 18, 2026 11:41
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 replace parameter to use_external_js_file(), use_external_css_file(), use_external_html_template(), use_external_file(), and use_bundled_html(), and plumb it through download/check helpers.
  • Update check_file_exists() to short-circuit when replace = TRUE and 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 a replace argument, but the abort text now tells users to “call this function again with replace = TRUE”. That makes the error message misleading in those contexts. Consider moving the replace hint 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.

Comment thread R/use_files_external.R Outdated
Comment thread R/use_files_external.R Outdated
Comment thread R/use_files_external.R
Comment thread man/use_files.Rd Outdated
- 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>
@ColinFay ColinFay merged commit 5e84f9d into master May 18, 2026
7 checks passed
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

Successfully merging this pull request may close these issues.

Add replace arg to use_external

2 participants