Skip to contents

This function takes a character vector containing the lines of a function definition and returns a character string containing only the lines belonging to the roxygen2 documentation (lines starting with "#'", possibly indented).

Usage

extract_roxygen2(func_def)

Arguments

func_def

A character vector containing the lines of a function definition; each element may itself hold several lines (LF or CRLF line endings), so a whole file as one string works too.

Value

A single character string containing the roxygen2 documentation lines, one per line (an empty string if there are none).

Examples

func_def <- c(
  "#' Extracts object from a response list",
  "#'",
  "#' @export",
  "object <- function(response) {",
  "  if (!is.list(response)) {",
  "    stop('Invalid response format. Expected list object.')",
  "  }",
  "}")

roxygen2_docu <- extract_roxygen2(func_def)
print(roxygen2_docu)
#> [1] "#' Extracts object from a response list\n#'\n#' @export"