## Keep parse data in non interactive sessions.
if (!interactive())
op <- options(keep.source = TRUE)
## Script with non empty comments.
fil <- tempfile(fileext = ".R")
cat(file = fil, "
#-
## here is foo
#-
foo <- function(x, y = 2)
x + y #addition
")
any_comments(getSourceData(fil))
## Script with embedded documentation.
fil <- tempfile(fileext = ".R")
cat(file = fil, "
###
### foo(x, y = 2)
###
## Adding two vectors
##
## Arguments
##
## x: a vector
## y: another vector
##
## Value
##
## Sum of the two vectors.
##
## Examples
##
## foo(1:5)
##
foo <- function(x, y = 2)
x + y
")
fooData <- getSourceData(fil)
## Elements present in the documentation
any_comments(fooData)
any_doc(fooData)
arguments_section_doc(fooData)
value_section_doc(fooData)
examples_section_doc(fooData)
formals_doc(fooData)
## Missing section title
description_section_doc(fooData)
Run the code above in your browser using DataLab