Learn R Programming

unpivotr (version 0.3.1)

pad: Pad a bag of cells with blanks

Description

When source data is sparse (e.g. spreadsheets from the 'tidyxl' package), the output of tidy_table may also be sparse. To fill the gaps with blank cells, use pad. Internally, pad is used to ensure that functions like offset and extend behave intuitively, as though blank cells do actually exist.

Usage

pad(cells, rows = cells$row, cols = cells$col)

Arguments

cells

Data frame, the cells to pad

rows

Numeric vector, the rows to be padded (existing cells will never be discarded, e.g. if this is 0, and no gaps will be left even if this is outside the original range of rows)

cols

Numeric vector, the columns to be padded (existing cells will never be discarded, e.g. if this is 0, and no gaps will be left even if this is outside the original range of columns)

Examples

Run this code
# NOT RUN {
cells <-
  tidy_table(purpose$`NNW WNW`) %>%
  dplyr::filter(!is.na(chr)) # Introduce 'holes' in the data
# Select a region with gaps
(bag <- dplyr::filter(cells, row %in% 2:4, col %in% 1:2))
# Pad the gaps
pad(bag) # By default, the selection is squared-off to its width and height
pad(bag, 0, 0) # Zeros are equivalent to the defaults
pad(bag, 2:5, 1:3) # Add a row and a column
pad(bag, 6, 4) # No gaps are left even when .rows or .cols are distant
# }

Run the code above in your browser using DataLab