View source: R/extract_r_code.R
extract_r_code | R Documentation |
This function takes an input string, detects R code and comments, and returns a character vector containing the R code and comments. The input string is split into lines based on newline characters, and each line is examined for R code and comment patterns. Only the lines that match either of these patterns are returned.
extract_r_code(input_string)
input_string |
A character string containing R code and comments, mixed with other text. The string may contain multiple lines separated by newline characters. |
A character vector containing R code and comment lines extracted from the input string. Each element in the vector corresponds to one line of code or a comment.
example_string <-
"This is a text string with R code and comments.\n
# A comment\n
x <- 5\
ny = 10\n
z <- x + y\n
Another line of text."
extract_r_code(example_string)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.