The assignment function simply associates a name with a value in the specified environment.
But the function of replacing the environment performs two functions: its main purpose is to change the environment of closing the function. This environment is where the function body code searches for global variables and functions. Typically, this envirionment is where the function was defined (so if you define it in a tooltip, it will use globalenv). As a βbonus," it simply assigns the .Environment attribute to other types of objects. This is pretty useless for most objects, but is used by formulas.
Secondly, it works almost like any other replacement function: if a name exists in the current environment, it changes it directly, otherwise a local copy is created and modifies it. Thus, in your case, it creates a local copy of the rect function and changes its environment. The original function remains unchanged.
# showing names replacement behavior f <- function() { names(letters) <- LETTERS letters
Tommy
source share