Learn R Programming

rtables (version 0.4.0)

sort_at_path: Sort substructure of a TableTree at a particular Path in the Tree.

Description

Sort substructure of a TableTree at a particular Path in the Tree.

Usage

sort_at_path(
  tt,
  path,
  scorefun,
  decreasing = NA,
  na.pos = c("omit", "last", "first")
)

Arguments

tt

TableTree (or related class). A TableTree object representing a populated table.

path

character. A vector path for a position within the structure of a tabletree. Each element represents a subsequent choice amongst the children of the previous choice.

scorefun

function. Scoring function, should accept the type of children directly under the position at path (either VTableTree, VTableRow, or VTableNodeInfo, which covers both) and return a numeric value to be sorted.

decreasing

logical(1). Should the the scores generated by scorefun be sorted in decreasing order. If unset (the default of NA), it is set to TRUE if the generated scores are numeric and FALSE if they are characters.

na.pos

character(1). What should be done with children (subtrees/rows) with NA scores. Defaults to "omit", which removes them, other allowed values are "last" and "first" which indicate where they should be placed in the order.

Value

A TableTree with the same structure as tt with the exception that the requested sorting has been done at path

Details

The path here can include "*" as a step, which means taht each child at that step will be separately sorted based on scorefun and the remaining path entries. This can occur multiple times in a path.