objects_size: Display sizes of objects in current R environment

View source: R/objects_size.R

objects_sizeR Documentation

Display sizes of objects in current R environment

Description

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.

Usage

objects_size(n = 10)

Arguments

n

Integer specifying the number of largest objects to display. Default: 10.

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.

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; NA for vectors and other objects).

See Also

utils::object.size(), base::ls(), base::rm()

Other utilities: .vif_to_df(), auc(), beowulf_cluster(), optimization_function(), prepare_importance_spatial(), rescale_vector(), root_mean_squared_error(), setup_parallel_execution(), standard_error(), statistical_mode(), thinning(), thinning_til_n()

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)

# Check all objects (up to 10 by default)
objects_size()


spatialRF documentation built on Dec. 20, 2025, 1:07 a.m.