R Language:A Diversion on Binding Values to Symbol

0

When you type `lm <- function(x) { x * x }`, you are creating a new function called `lm`. This function is defined in the global environment. When you type `lm`, R searches the global environment for a symbol named `lm`. It finds the function that you just created and returns it.

The `lm` function that you created is different from the `lm` function that is in the `stats` package. The `lm` function in the `stats` package is a statistical function that is used to fit linear models. The `lm` function that you created is a simple function that just squares its input.

The reason that R doesn't give the symbol `lm` the value of the `lm` function in the `stats` package is because the `lm` function in the `stats` package is not in the global environment. The `lm` function in the `stats` package is in the namespace of the `stats` package. The namespace of a package is a special environment that contains all of the objects that are exported from the package.

When R searches for a symbol, it first searches the global environment. If it doesn't find the symbol in the global environment, it then searches the namespaces of the packages on the search list. The search list is a list of all of the packages that are loaded in R. The order of the packages on the search list matters. R will search the namespaces of the packages in the order that they are listed on the search list.

In this case, the `lm` function that you created is in the global environment. The `lm` function in the `stats` package is in the namespace of the `stats` package. Since the `lm` function that you created is in the global environment, R will find it first and return it.

Post a Comment

0Comments
Post a Comment (0)