Write a R program to get the details of the objects in memory

1. Introduction

This R program is designed to retrieve and display details of all objects currently stored in memory. It provides information such as the object's name, type, and size.

2. Program Steps

1. List all objects in the current R environment.

2. Iterate through each object and retrieve its details.

3. Display the details of each object.

3. Code Program

# List all objects in the current environment
objects_in_memory <- ls()

# Iterate over each object and display its details
for (obj_name in objects_in_memory) {
    # Get the object by its name
    obj <- get(obj_name)

    # Display the object's name, type, and size
    cat("Name:", obj_name, "\tType:", typeof(obj), "\tSize:", object.size(obj), "bytes\n")
}

Output:

Name: [Object Name]    Type: [Object Type]    Size: [Object Size] bytes
... (more objects)

Explanation:

1. ls(): Lists all objects available in the current R environment.

2. for (obj_name in objects_in_memory): Iterates through each object.

3. get(obj_name): Retrieves the object by its name.

4. cat("Name:", obj_name, "\tType:", typeof(obj), "\tSize:", object.size(obj), "bytes\n"): Displays the name, type, and size of each object in memory.


Comments