find_gran: Find out granularity of a string vector

View source: R/sum_str.R

find_granR Documentation

Find out granularity of a string vector

Description

This helper function takes a string (vector) as an input and searches for the highest or lowest granularity. Granularity is defined in terms of a hash/ space sequence (see sum_str). The search is implemented using a recursive approach.

Usage

find_gran(direction = "down", highest = 3, lowest = 1, lines)

Arguments

direction

either "up" or "down". Down means the algorithm starts with the pattern containing a certain number of hashes (specified in highest) and searches for a regex match. If it can't find one, it reduces the number of hashes by one and searches again, until it finds a pattern.

highest

The highest level of granularity to search for.

lowest

The lowest level of granularity to search for.

lines

a character vector containing the lines to match against.

Examples

  strcode:::find_gran("down", highest = 3, lowest = 1, lines = c("##  .", "#   _"))

lorenzwalthert/strcode documentation built on May 11, 2023, 12:10 a.m.