inspect_mem: Summary and comparison of memory usage of dataframe columns

View source: R/inspect_mem.R

inspect_memR Documentation

Summary and comparison of memory usage of dataframe columns

Description

For a single dataframe, summarise the memory usage in each column. If two dataframes are supplied, compare memory usage for columns appearing in both dataframes. For grouped dataframes, summarise the memory usage separately for each group.

Usage

inspect_mem(df1, df2 = NULL)

Arguments

df1

A data frame.

df2

An optional second data frame with which to comparing memory usage. Defaults to NULL.

Details

For a single dataframe, the tibble returned contains the columns:

  • col_name, a character vector containing column names of df1.

  • bytes, integer vector containing the number of bytes in each column of df1.

  • size, a character vector containing display-friendly memory usage of each column.

  • pcnt, the percentage of the dataframe's total memory footprint used by each column.

For a pair of dataframes, the tibble returned contains the columns:

  • col_name, a character vector containing column names of df1 and df2.

  • size_1, size_2, a character vector containing memory usage of each column in each of df1 and df2.

  • pcnt_1, pcnt_2, the percentage of total memory usage of each column within each of df1 and df2.

For a grouped dataframe, the tibble returned is as for a single dataframe, but where the first k columns are the grouping columns. There will be as many rows in the result as there are unique combinations of the grouping variables.

Value

A tibble summarising and comparing the columnwise memory usage for one or a pair of data frames.

Author(s)

Alastair Rushworth

See Also

show_plot

Examples

# Load dplyr for starwars data & pipe
library(dplyr)

# Single dataframe summary
inspect_mem(starwars)

# Paired dataframe comparison
inspect_mem(starwars, starwars[1:20, ])

# Grouped dataframe summary
starwars %>% group_by(gender) %>% inspect_mem()

inspectdf documentation built on Aug. 9, 2022, 9:05 a.m.