If you’re using S7 in an R package and registering methods for replacement operators ($<-, [[<-, [<-), you’ve probably hit this:
W checking replacement functions ...
Error in get(f, envir = code_env) : invalid first argument
The argument of a replacement function which corresponds to the right
hand side must be named 'value'.Your code is fine. This is a bug in R CMD check.
What’s going on
When S7 registers a replacement method, it stores a function object in the S3 methods table. R CMD check’s checkReplaceFuns() expects string names there. It coerces the function to "", calls get(""), and crashes. The “must be named value” message is boilerplate that prints after the crash. It never actually inspected your function signature.
Is there a fix?
Yes. Martin Maechler fixed this in R-devel across three commits1 2 3:
From the R-devel NEWS (July 11, 2025):
tools::checkReplaceFuns()now deals better with replacement methods not available as regular functions in the namespace.
This ships in R 4.6. It is not in R 4.5.x or earlier.
The workaround
Move your replacement method registrations into .onLoad(). R CMD check only scans top-level source assignments, so methods registered at load time bypass the check entirely while dispatching identically at runtime.
Read-only methods ($, [[, names) are unaffected and can stay at the top level.
# R/methods.R
S7::method(`$`, MyClass) <- function(x, name) { S7::prop(x, name) }
S7::method(`[[`, MyClass) <- function(x, i, ...) { S7::prop(x, i) }
S7::method(names, MyClass) <- function(x) { names(S7::props(x)) }
# Implementations for replacement ops (registered in zzz.R)
.my_dollar_set <- function(x, name, value) { S7::prop(x, name) <- value; x }
.my_bracket2_set <- function(x, i, ..., value) { S7::prop(x, i) <- value; x }
# R/zzz.R
.onLoad <- function(libname, pkgname) {
S7::methods_register()
S7::method(`$<-`, MyClass) <- .my_dollar_set
S7::method(`[[<-`, MyClass) <- .my_bracket2_set
}Fin
This is one of those rough edges that comes with adopting a new object system before the toolchain has fully caught up. S7 itself is doing the right thing; R CMD check just hasn’t learned to look for methods stored as function objects rather than name strings. The .onLoad() workaround is clean enough to live with until R 4.6 ships the proper fix.
References
- RConsortium/S7#569: Hadley’s report from stringr, where this first surfaced in a widely used package.
- RConsortium/S7#549: The original bug report, closed once the R-devel fix landed.
- RConsortium/S7#562: Discussion of the
.onLoad()workaround and its trade-offs.
Footnotes
Initial fix to
checkReplaceFuns()in R-devel (svn 88398, Jul 10, 2025). View commit.↩︎Follow-up amendment (svn 88404, Jul 11, 2025). View commit.↩︎
Reporting improvement (svn 88418, Jul 16, 2025). View commit.↩︎