Skip to contents

This function generates an Excel workbook containing Harvey Balls based on the provided data.

Usage

shelf_render_harvey_balls_xlsx(
  shelf,
  indices_id = "indices_boxed",
  n_bins = 10L,
  absolute = TRUE,
  file = NULL
)

Arguments

shelf

Shelf data. Result from rack_extract_shelf().

indices_id

Character. Name of the shelf element containing boxed indices to build Harvey balls for. Usually it's called "indices_boxed".

n_bins

Numeric. A numeric scalar representing the number of place holder bins to use. Default is 10.

absolute

A logical scalar. If TRUE, the min and max formulas will use 0 and 1, respectively. If FALSE, the formulas will use the minimum and maximum values within the specified bin.

file

The file path where the workbook will be saved. If NULL, the workbook object is returned.

Value

Invisibly returns the file path if the workbook is saved, otherwise returns the workbook object.

Examples

out_dir <- file.path(tempdir(), "g6tr.segmentation")
if (!dir.exists(out_dir)) dir.create(out_dir, recursive = TRUE)

library(dplyr)

shelf_data <-
  example_seg_rack_extended |>
  filter(n_seg == 4) |>
  rack_extract_shelf()

# set some segment names   
levels(shelf_data$segments) <- c("Blue", "Green", "Yellow", "Red")

# write directly to a file
shelf_render_harvey_balls_xlsx(
  shelf_data,
  file = file.path(out_dir, "example_harvey_balls.xlsx")
)
#> Warning: NAs introduced by coercion
#> Warning: NAs introduced by coercion
#> Warning: NAs introduced by coercion

if (FALSE) { # \dontrun{
# first get a workbook object and then write
wb <- shelf_render_harvey_balls_xlsx(shelf_data)
openxlsx::saveWorkbook(
  wb,
  file.path(out_dir, "example_harvey_balls.xlsx"),
  overwrite = TRUE
)
} # }

# cleanup
unlink(out_dir)