test_matrix_form: Create spoof matrix form from a data frame

test_matrix_formR Documentation

Create spoof matrix form from a data frame

Description

Useful functions for writing tests and examples, and a starting point for more sophisticated custom matrix_form methods.

Usage

basic_matrix_form(
  df,
  indent_rownames = FALSE,
  parent_path = NULL,
  ignore_rownames = FALSE,
  add_decoration = FALSE,
  fontspec = font_spec(),
  split_labels = NULL,
  data_labels = NULL,
  num_rep_cols = 0L
)

basic_listing_mf(
  df,
  keycols = names(df)[1],
  add_decoration = TRUE,
  fontspec = font_spec()
)

Arguments

df

(data.frame)
a data frame.

indent_rownames

(flag)
whether row names should be indented. Being this used for testing purposes, it defaults to FALSE. If TRUE, it assigns label rows on even lines (also format is "-" and value strings are ""). Indentation works only if split labels are used (see parameters split_labels and data_labels).

parent_path

(string)
parent path that all rows should be "children of". Defaults to NULL, as usually this is not needed. It may be necessary to use "root", for some specific scenarios.

ignore_rownames

(flag)
whether row names should be ignored.

add_decoration

(flag)
whether adds title and footer decorations should be added to the matrix form.

fontspec

(font_spec)
a font_spec object specifying the font information to use for calculating string widths and heights, as returned by font_spec().

split_labels

(string)
indicates which column to use as split labels. If NULL, no split labels are used.

data_labels

(string)
indicates which column to use as data labels. It is ignored if no split_labels is present and is automatically assigned to "Analysis method" when split_labels is present, but data_labels is NULL. Its direct column name is used as node name in "DataRow" pathing. See mf_rinfo() for more information.

num_rep_cols

(numeric(1))
Number of columns to be treated as repeating columns. Defaults to 0 for basic_matrix_form and length(keycols) for basic_listing_mf. Note repeating columns are separate from row labels if present.

keycols

(character)
a vector of df column names that are printed first and for which repeated values are assigned "". This format is characteristic of a listing matrix form.

Details

If some of the column has a obj_format assigned, it will be respected for all column values except for label rows, if present (see parameter split_labels).

Value

A valid MatrixPrintForm object representing df that is ready for ASCII rendering.

A valid MatrixPrintForm object representing df as a listing that is ready for ASCII rendering.

Functions

  • basic_listing_mf(): Create a MatrixPrintForm object from data frame df that respects the default formats for a listing object.

Examples

mform <- basic_matrix_form(mtcars)
cat(toString(mform))


# Advanced test case with label rows
library(dplyr)
iris_output <- iris %>%
  group_by(Species) %>%
  summarize("all obs" = round(mean(Petal.Length), 2)) %>%
  mutate("DataRow_label" = "Mean")
mf <- basic_matrix_form(iris_output,
  indent_rownames = TRUE,
  split_labels = "Species", data_labels = "DataRow_label"
)
cat(toString(mf))

mform <- basic_listing_mf(mtcars)
cat(toString(mform))


formatters documentation built on Sept. 13, 2024, 1:10 a.m.