countSwitches: create an incremented Counter, based on Start/Stop Markers

View source: R/countSwitches.R

countSwitchesR Documentation

create an incremented Counter, based on Start/Stop Markers

Description

This function aims at identifying sections and sub-sections numbers, based on markers of section starts and ends.

Given a data frame, and the name of a column giving the start/stop markers, it will add columns giving infos about the successive section levels

Usage

countSwitches(
  data,
  colNm,
  sttMark,
  endMark,
  includeStt = TRUE,
  includeEnd = TRUE
)

Arguments

data

A data frame containing the column to process.

colNm

A string specifying the column name in 'data' to evaluate.

sttMark

A value indicating the start of a series.

endMark

A value indicating the end of a series.

includeStt

Logical. Should the start marker be included as part of the series? Default is 'TRUE'.

includeEnd

Logical. Should the end marker be included as part of the series? Default is 'TRUE'.

Value

A modified version of the input data frame with additional columns including:

  • 'catLvl': The current series level calculated as the difference between the cumulative counts of start and end markers.

  • 'lvl_1', 'lvl_2', 'lvl_3': Final series counts returned for each respective level.

Note

This function is currently mostly useful internally, to perform foldAllBr().

Examples

# example code
library(dplyr)
tribble(
~step
, "start"
, "content of section 1"
, "start"
, "subsection 1.1"
, "end"
, "end"
, "out of any section"
, "start"
, "section 2"
, "start"
, "subsection 2.1"
, "end"
, "start"
, "subsection 2.2"
, "end"
, "end"
) %>%
	countSwitches(colNm = "step", "start", "end")


R.AlphA.Home documentation built on April 3, 2025, 5:53 p.m.