Skip to content

Refine assert_function_expects error handling and tests#144

Merged
selkamand merged 6 commits intomainfrom
codex/add-assert_function_expects-to-assertion-package
Feb 8, 2026
Merged

Refine assert_function_expects error handling and tests#144
selkamand merged 6 commits intomainfrom
codex/add-assert_function_expects-to-assertion-package

Conversation

@selkamand
Copy link
Owner

Motivation

  • Ensure error messages for missing required function arguments are constructed deterministically inside the validator rather than via deferred glue evaluation, so tests can assert on concrete messages and behaviour is clearer.

Description

  • Compute the missing required argument names and counts inside function_expects_advanced() and return a formatted message that includes the missing count and a backticked list of missing names.
  • Update R/assert_functions.R to embed the computed missing_count and missing_args into the returned error string instead of relying on deferred glue placeholders.
  • Broaden and clarify tests in tests/testthat/test-assert_functions.R to cover defaults, functions with only ..., and non-function inputs, replacing several snapshots with explicit expect_error() checks for assert_function_expects() while keeping snapshot coverage for assert_function_expects_n_arguments().
  • Add/update the snapshot file tests/testthat/_snaps/assert_functions.md to retain existing snapshot coverage for the n-arguments assertion.

Testing

  • Ran devtools::document() which completed and updated documentation successfully.
  • Ran devtools::test() and all tests passed (PASS 978, FAIL 0, WARN 0, SKIP 0).
  • Ran devtools::check() which completed but reported one WARNING (qpdf missing for PDF size checks) and one NOTE (future timestamps); R CMD check surfaced the WARNING which caused the check command to exit non-zero.

Codex Task

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 54c5a86e6e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +72 to +78
func_required_arg_names <- function(func){
args <- formals(args(func))
if(length(args) == 0){
return(character(0))
}
required_args <- args[vapply(args, is.symbol, FUN.VALUE = TRUE)]
required_args <- names(required_args)

Choose a reason for hiding this comment

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

P2 Badge Fix required-arg detection for symbol defaults

func_required_arg_names() uses is.symbol to decide which formals are “required.” In R, a default like x = mean or x = y is stored as a symbol too, so this logic treats those defaulted args as required and assert_function_expects() will incorrectly report them missing when callers omit them. This only shows up for functions whose defaults are symbols, but it makes the new assertion reject valid functions. Consider checking for a missing default (e.g., identical(arg, quote(expr=))) rather than is.symbol.

Useful? React with 👍 / 👎.

@selkamand
Copy link
Owner Author

@codex add examples to the assert_function_expects roxygen comment

@chatgpt-codex-connector
Copy link

Summary

Testing

  • Not run (not requested).

View task →

@selkamand selkamand merged commit 14951a9 into main Feb 8, 2026
7 checks passed
@selkamand selkamand deleted the codex/add-assert_function_expects-to-assertion-package branch February 8, 2026 13:17
@selkamand selkamand linked an issue Feb 8, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

assert_function_expects_specific_arguments

1 participant