R Program to get the details of the objects in memory


February 5, 2023, Learn eTutorial
1912

How to get the details of the objects in memory using R program?

Here we are accessing the memory object details using the R program. For that, we are using built-in functions ls() means list objects for this calculation.

  • The ls() function helps to return a vector of character strings with the names of the objects in the specified environment.

If we call the ls() function without arguments it will return all the user-defined functions and datasets in the directory which is now active. The ls.str is used for a long listing based on the str. In this R program, we directly give the values to variables name, num1, num2, and nums, And print the function result.

Here the variable name is assigned with a string, num1 with an integer value, num2 with a floating value, and nums with vector values. Then we call the function Is() in R for object listing. then we call the ls.str() function for displaying the memory object listings.

ALGORITHM

STEP 1: Assign variable name,num1,num2, nums with corresponding values

STEP 2: Call the built-in functions ls() for a listing of objects

STEP 3: First print given objects

STEP 4: Call the built-in functions ls.str() for string-based long listing

R Source Code

                                          name = "Python"; 
num1 =  8; 
num2 =  1.5
nums = c(10, 20, 30, 40, 50, 60)
print(ls())
print("Details of the objects in memory:")
print(ls.str())

                                      

OUTPUT

[1] "num1"   "num2"   "name" "nums"
[1] "Details of the objects in memory:"
num1 :  num 8
num2 :  num 1.5
name :  chr "Python"
nums :  num [1:6] 10 20 30 40 50 60