Skip to contents

Find path to a particular kind of item

Usage

path_to(items, is_fn, ..., all = FALSE)

get_item(items, path)

set_item(items, path, value)

get_container(items, path)

get_which(path)

Arguments

items

A list of latex items.

is_fn

Which test function to use.

...

Additional parameters to pass to is_fn.

all

Find all matching, or the first?

path

Integer vector of subitems

value

A LaTeX2item to set as a value.

Value

path_to() returns the recursive path to the first example matching the is_fn conditions, or a list of paths to all matching items.

get_item() returns the item at the given path.

set_item() replaces the item at the given path, and returns the modified version of items.

get_container() returns the item containing the given path

get_which() returns the index of the item within its container.

Details

path_to() does a recursive search in the order items appear in the deparse.

Examples

latex <- kableExtra::kbl(mtcars[1:2, 1:2], format = "latex", caption = "Sample table")
parsed <- parseLatex(latex)
parsed
#> \begin{table}
#> 
#> \caption{Sample table}
#> \centering
#> \begin{tabular}[t]{l|r|r}
#> \hline
#>   & mpg & cyl\\
#> \hline
#> Mazda RX4 & 21 & 6\\
#> \hline
#> Mazda RX4 Wag & 21 & 6\\
#> \hline
#> \end{tabular}
#> \end{table} 
path <- path_to(parsed, is_fn = is_env,
                        envtypes = "tabular")
get_item(parsed, path)
#> ENVIRONMENT: \begin{tabular}[t]{l|r|r}
#> \hline
#>   & mpg & cyl\\
#> \hline
#> Mazda RX4 & 21 & 6\\
#> \hline
#> Mazda RX4 Wag & 21 & 6\\
#> \hline
#> \end{tabular}