Skip to content

Support existing functions in crate() - #37

Merged
shikokuchuo merged 10 commits into
mainfrom
existing-fns
Jul 22, 2026
Merged

shikokuchuo merged 10 commits into
mainfrom
existing-fns

Conversation

@shikokuchuo

Copy link
Copy Markdown
Member

Closes #36. See the issue for the full design history and motivation.

crate() no longer requires .fn to be defined inside the call. Existing functions are handled by type:

  • Plain closures are re-environed into the crate's evaluation environment, equivalent to the previous crate(rlang::set_env(fn)) workaround.
  • Namespace functions and primitives are wrapped in a thin closure that delegates to them, leaving their original environment untouched.
  • Existing crates are passed through unchanged.
  • Supplying ... data that would be unreachable from the resulting crate (existing crate, namespace function, or primitive) is an error.

The factory-closure pitfall (e.g. stats::ecdf() results losing captured state) is documented with an example rather than guarded heuristically, as discussed in #36.

Comment thread R/crate.R Resolved

@hadley hadley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This approach is fine with me. I assume we should do a revdep pass for purrr just in case any CRAN package relies on the existing behaviour for function factories?

Comment thread R/crate.R Resolved
Comment thread R/crate.R Resolved
Comment thread R/crate.R Resolved
Comment thread R/crate.R Resolved
Comment thread R/crate.R Resolved
Comment thread R/crate.R Resolved
Comment thread R/crate.R Resolved
Comment thread R/crate.R Resolved
@shikokuchuo

Copy link
Copy Markdown
Member Author

Revdeps for both carrier and purrr come back clean. I checked purrr using cloud_check(revdep_packages = cran_revdeps("purrr")) from this branch.

@shikokuchuo
shikokuchuo merged commit e4fa846 into main Jul 22, 2026
11 checks passed
@shikokuchuo
shikokuchuo deleted the existing-fns branch July 22, 2026 11:18
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.

Support passing existing functions to crate()

3 participants