Variables are used to store data in any programming language. They are the named spaces in the memory which can referenced and manipulated later in the code.
This recipe specifically deals with how to remove all variables from the session
Assigning values with three different data types to variables
a = 'hello' b = 3.5 c = as.integer(8.9)
We use cat() function to print the variables to check whether assignment was done or not
hello 3.5 8
We use rm() function to remove variables while the arguement "list = ls()" will make sure all of the variables are removed from the list. ls() gives the list of all the variables in the session. This would also remove functions assigned in the session.
rm(list = ls())
To check whether the variable is removed or not, we use cat() function
Error in cat(a): object 'a' not found Traceback: 1. cat(a)
Error in cat(b): object 'b' not found Traceback: 1. cat(b)
Error in cat(c): argument 1 (type 'builtin') cannot be handled by 'cat' Traceback: 1. cat(c)
Hence, we can conclude that all the variables have been removed in the session