Rdo_locate_leaves {Rdpack} | R Documentation |
Find leaves of an Rd object using a predicate
Description
Apply a function to the character leaves of an Rd object and return the indices of those for which the result is TRUE.
Usage
Rdo_locate_leaves(object, f = function(x) TRUE)
Arguments
object |
the object to be examined, usually a list. |
f |
a function (predicate) returning TRUE for elements with the desired property. |
Details
object
can be any list whose elements are character strings or
lists. The structure is examined recursively. If object
is a
character vector, it is enclosed in a list.
This function provides a convenient way to locate leaves of an Rd
object with a particular content. The function is not limited to Rd
objects but it assumes that the elements of object
are either
lists or charater vectors and currently does not check if this is the
case.
todo: describe the case of list()
(Rd_tag
'ed.)
Value
a list of the positions of the leaves for which the predicate gives
TRUE
. Each position is an integer vector suitable for the
"[["
operator.
Author(s)
Georgi N. Boshnakov
Examples
dummyfun <- function(x) x
fn <- tempfile("dummyfun", fileext = "Rd")
reprompt(dummyfun, filename = fn)
rdo <- tools::parse_Rd(fn)
f <- function(x) Rdo_is_newline(x)
nl <- Rdo_locate_leaves(rdo, f )
length(nl) # there are quite a few newline leaves!
unlink(fn)