Skip to contents

This function extracts and separates commented and non-commented parts from a given vector of texts. It uses a specified delimiter pair to identify comments and returns a data frame with the full text, extracted comments, and remaining code lines.

Usage

separate_commented_lines(texts, delim_pair = c(`/*` = "*/"), .verbose = T)

Arguments

texts

character vector containing text with possible comments.

delim_pair

character A named character vector of length 1, where the name is the opening delimiter (e.g., "/*") and the value is the closing delimiter (e.g., "*/").

.verbose

logical, default = TRUE Return a progress bar if set to TRUE

Value

A data frame with three columns:

text

The original text.

comments

The extracted comments, concatenated together if multiple are found.

codelines

The remaining text after removing comments.

Examples

if (FALSE) { # \dontrun{
texts <- c(
  "Code snippet /* first comment */ and more code /* second comment */",
  "Another line /* only a comment */",
  "A line with no comments", " here one start /* commented ", " some commented line", " */"
)

separate_commented_lines(texts, delim_pair = c("/*" = "*/"), .verbose = FALSE)
} # }