Skip to content
Prev 61490 / 63421 Next

WISH: Optional mechanism preventing var <<- value from assigning non-existing variable

On 19/03/2023 2:43 p.m., Gabriel Becker wrote:
This sounds like a linter would be appropriate:  any time you make an 
assignment that goes more than one level up, it warns you about it.

Other linter rules could limit the destination in other ways, e.g. 
assigning to globalenv() or things in the search list could be disallowed.

Another error I've made a few times is to use "<-" by mistake when "<<-" 
was intended.  A linter could detect this by seeing both `x <- value1` 
and `x <<- value2` in the same context.  That's legal, but (for me at 
least) it usually indicates that one of them is a typo.

Duncan Murdoch