Skip to content
Prev 62194 / 63421 Next

[EXTERNAL] Re: NOTE: multiple local function definitions for ?fun? with different formal arguments

Hopefully to too much of a tangent: A related problem this check doesn?t catch is accidental top-level redefinitions in package code, such as

## a.R:
helper <- function() 1

f <- function() {
helper()
}
# ?cool, f() must return 1"

## b.R:
helper <- function(x) 2

g <- function() {
helper()
}
# ?cool, g() must return 2"

## Runtime: 
# > c(pkg::f(), pkg::g())
# [1] 2 2
# ?oh right, only the last definition of helper() is used?
 
I?ve seen several variants of this issue in code from folks who are new to package development, especially if they're naively refactoring something that started out as an interactively-run analysis. Collaborators who are puzzled by it get my ?packages are collections of objects not sequences of expressions, yes that needs to be in your mental model, here?s the link to RWE again? talk, but I would be happy to be able to point them to a check result to go along with it.

I don?t think this is grounds on its own to change a 20-year precedent, but in case anyone is collecting wishlist reasons to make the check look harder...

Thanks,
Chris