read_md_to_df_str: Read Markdown File and Convert to a Structured DataFrame

View source: R/md_to_df_str.R

read_md_to_df_strR Documentation

Read Markdown File and Convert to a Structured DataFrame

Description

Reads a Markdown file using readLines and parses the content into a structured DataFrame based on the Markdown headings. The function allows optional aggregation of content under each heading and flexible reading of files with additional readLines arguments.

Usage

read_md_to_df_str(
  file,
  summarize = TRUE,
  collapse = ", ",
  readLines_args = list()
)

Arguments

file

A character string naming a file, a connection, or literal data (either a single string or a raw vector) to be read.

summarize

Logical, if TRUE, content under each heading is summarized into a single cell per heading level; if FALSE, each line retains its own row in the output DataFrame.

collapse

The string to use when collapsing multiple lines of content under each heading when summarize = TRUE.

readLines_args

A list of additional arguments to pass to readLines(). This can include any parameter that readLines accepts like encoding, etc.

Value

A data.frame where each row corresponds to a heading or content line. If summarize is TRUE, each heading level is condensed into a single entry. The columns of the DataFrame represent the hierarchical levels (headings) and the content under these headings.

Examples

# Read a local Markdown file and convert to a DataFrame
# df <- read_md_to_df_str("path/to/your/file.md")

# Read a Markdown file with content summarization disabled
# df <- read_md_to_df_str("path/to/your/file.md", summarize = FALSE)

# Read a Markdown file with specific encoding
# df <- read_md_to_df_str("path/to/your/file.md", readLines_args = list(encoding = "UTF-8"))


Lightbridge-KS/lbdoc documentation built on May 16, 2024, 3:03 p.m.