Returns a summary of objects in the current R workspace, sorted from largest to smallest by memory size. Useful for identifying memory-intensive objects and diagnosing memory issues.
Value
Data frame with object names as row names and four columns:
Type: Object class (e.g., "data.frame", "matrix", "list").Size: Memory size with automatic unit formatting (e.g., "1.2 Mb", "500 bytes").Length/Rows: Number of elements (for vectors) or rows (for data frames/matrices).Columns: Number of columns (for data frames/matrices;NAfor vectors and other objects).
Details
This utility function helps monitor memory usage by displaying the largest objects in your workspace. It's particularly useful for:
Identifying memory bottlenecks during large spatial analyses
Deciding which objects to remove to free memory
Understanding the memory footprint of different data structures
The function examines all objects in the global environment (.GlobalEnv) and calculates their memory usage using utils::object.size(). Objects are automatically sorted by size in descending order.
Examples
# Create some objects of different sizes
small_vector <- runif(100)
medium_matrix <- matrix(runif(10000), 100, 100)
large_matrix <- matrix(runif(100000), 1000, 100)
# View the 5 largest objects
objects_size(n = 5)
#> Type Size Length/Rows Columns
#> maxicheck function 784 bytes NA NA
#> load function 616 bytes NA NA
#> plants_xy data.frame 5.4 Kb 227 3
#> plants_distance matrix 431.7 Kb 227 227
#> plants_df data.frame 38.9 Kb 227 21
# Check all objects (up to 10 by default)
objects_size()
#> Type Size Length/Rows Columns
#> maxicheck function 784 bytes NA NA
#> load function 616 bytes NA NA
#> plants_xy data.frame 5.4 Kb 227 3
#> plants_distance matrix 431.7 Kb 227 227
#> plants_df data.frame 38.9 Kb 227 21
#> plants_rf_spatial rf 176.6 Mb 23 NA
#> plants_rf rf 144.7 Mb 22 NA
#> plants_response character 136 bytes 1 NA
#> plants_predictors character 1.5 Kb 17 NA
#> minicheck function 1.3 Kb NA NA