| 1 |
% Generated by roxygen2: do not edit by hand |
| 2 |
% Please edit documentation in R/string.R |
| 3 |
\name{split_source} |
| 4 |
\alias{split_source} |
| 5 |
\title{Split source lines into complete expressions} |
| 6 |
\usage{ |
| 7 |
split_source(x, merge_comments = FALSE, line_number = FALSE) |
| 8 |
} |
| 9 |
\arguments{ |
| 10 |
\item{x}{A character vector of R source code.} |
| 11 |
|
| 12 |
\item{merge_comments}{Whether to merge consecutive lines of comments as a |
| 13 |
single expression to be combined with the next non-comment expression (if |
| 14 |
any).} |
| 15 |
|
| 16 |
\item{line_number}{Whether to store the line numbers of each expression in |
| 17 |
the returned value.} |
| 18 |
} |
| 19 |
\value{ |
| 20 |
A list of character vectors, and each vector contains a complete R |
| 21 |
expression, with an attribute \code{lines} indicating the starting and ending |
| 22 |
line numbers of the expression if the argument \code{line_number = TRUE}. |
| 23 |
} |
| 24 |
\description{ |
| 25 |
Parse the lines of code one by one to find complete expressions in the code, |
| 26 |
and put them in a list. |
| 27 |
} |
| 28 |
\examples{ |
| 29 |
code = c("# comment 1", "# comment 2", "if (TRUE) {", "1 + 1", "}", "print(1:5)") |
| 30 |
xfun::split_source(code) |
| 31 |
xfun::split_source(code, merge_comments = TRUE) |
| 32 |
} |