Skip to content

fix StatLm duplicate formula arg when lm.args supplies formula#191

Open
jiyunson wants to merge 1 commit into
ProjectMOSAIC:mainfrom
jiyunson:fix/lm-args-formula-conflict
Open

fix StatLm duplicate formula arg when lm.args supplies formula#191
jiyunson wants to merge 1 commit into
ProjectMOSAIC:mainfrom
jiyunson:fix/lm-args-formula-conflict

Conversation

@jiyunson

@jiyunson jiyunson commented Jul 2, 2026

Copy link
Copy Markdown

Hey Randall -- just a tiny edit! Thanks as always for all your awesome work on mosaic/ggformula/etc.

Summary

When lm.args = list(formula = y ~ poly(x, 2)) is passed to gf_lm() or stat_lm(), the call to do.call(stats::lm, c(base.args, lm.args)) fails with:

formal argument "formula" matched by multiple actual arguments

because base.args already contains formula = y ~ x (the default), and lm.args adds a second formula key.

The fix is one line: drop base.args$formula before merging when lm.args already provides its own formula, so the user-supplied formula wins cleanly.

Reproduction

library(ggformula)
data(KidsFeet, package = "mosaicData")

# Before fix: error "matched by multiple actual arguments"
# After fix: draws a quadratic fit
gf_point(length ~ width, data = KidsFeet) |>
  gf_lm(lm.args = list(formula = y ~ poly(x, 2)))

Note: the formula = y ~ poly(x, 2) direct-param syntax already works; this fixes the lm.args path to be consistent.

Test plan

  • Verify lm.args = list(formula = ...) no longer errors
  • Verify lm.args = list(formula = ...) produces the same fit as formula = ... directly
  • Verify default behavior (lm.args = list()) is unchanged

🤖 Generated with Claude Code

When lm.args = list(formula = y ~ poly(x, 2)) is passed, do.call(lm,
c(base.args, lm.args)) produced a list with two 'formula' keys, causing:
  "formal argument 'formula' matched by multiple actual arguments"

Drop base.args$formula before merging when lm.args already provides one,
so the user-supplied formula wins cleanly.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@rpruim

rpruim commented Jul 2, 2026

Copy link
Copy Markdown

Thanks.

I'm traveling the next two weeks, and I may not get a chance to look at this until I return.

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.

2 participants