R Environment

In this tutorial you will learn about the R Environment and its application with practical example.

R Environment

In R, as soon as R interpreter is started a run time environment is automatically created. This run time environment holds up a collection of all run-time entities being created including functions, variables etc.

R Global Environment

The top level environment, when the R interpreter is started is termed as global environment. This can be referred to as .GlobalEnv in R program, a

R ls() function

In R, ls() function is used to list all of the variables and functions available in current environment.

Example:-

r_ls_function

R environment() function

The environment() function is used to show current environment.

Example:-

R Environments Cascading

In R, whenever a new function is defined, a new environment is created for it. An environment actually has a frame, that contains all of the entities being defined, it also contains a pointer to its enclosing (parent) environment. In R, defining a function inside another function results in cascading of environment.

Example:-

Here, we have function named funA which is accepting a parameter “a”, inside this we have function named funB which accepting parameter “b”.

Let’s run the above program to see the output –

Output:-

r_environment_cascading

In this tutorial we have learn about the R Environment and its application with practical example. I hope you will like this tutorial.