Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

find_pos_id_to_keep

Find the pos ids to keep


Description

To make a parse table shallow, we must know which ids to keep. split(cumsum(pd_parent_first$parent == 0)) above puts comments with negative parents in the same block as proceeding expressions (but also with positive). find_pos_id_to_keep() must hence always keep negative comments. We did not use split(cumsum(pd_parent_first$parent < 1)) because then every top-level comment is an expression on its own and processing takes much longer for typical roxygen annotated code.

Usage

find_pos_id_to_keep(pd)

Arguments

pd

A temporary top level nest where the first expression is always a top level expression, potentially cached.

Details

Note that top-level comments above code have negative parents (the negative value of the parent of the code expression that follows after, a nother comment might be in the way though), all comments that are not top level have positive ids. All comments for which no code follows afterwards have parent 0.

Examples

styler:::get_parse_data(c("#", "1"))
styler:::get_parse_data(c("c(#", "1)"))
styler:::get_parse_data(c("", "c(#", "1)", "#"))

styler

Non-Invasive Pretty Printing of R Code

v1.4.1
MIT + file LICENSE
Authors
Kirill Müller [aut], Lorenz Walthert [cre, aut]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.