Create a summary of one or multiple code files based on the section separators and their titles.
sum_str(path_in = getSourceEditorContext()$path, file_in_extension = ".R", dir_out = "", file_out = NULL, file_out_extension = "", width = NULL, rm_rh_hashes = TRUE, rm_rh_spaces = TRUE, rm_break_anchors = TRUE, line_nr = TRUE, granularity = 3, last_sep = FALSE, title = TRUE, header = TRUE, ...)
sum_str
is called.file_in
is NULL
, all files with the
file_in_extension
are considered, defaults to ".R".NULL
, the name will be paste0("code-summary_", file_in)
.
If dir_out
is set to "", file_out
can be set to
"object" and the output of the function will be returned as an
object instead of just printed to the console with cat
. This is
useful if output should be assigned to an object. If not set to "object",
cat
will be used.list.files
for reading in multiple files.To create the summary, sum_str
uses regular expressions.
Hence it is crucial that the code separators and the separator titles
match the regular expression pattern. We recommend inserting
separators and their titles using the RStudio Add-in that is contained
in this package. The definition is rather intuitive as can be seen in the
example section below. However, we shall provide a formal definition here
as well.
.
or _
.
.
or _
.
Lines that do not satisfy these requirements (e.g. do not start with #s,
do not contain the right number of spaces after the #, indent before any #
ect.) are not considered by sum_str
.
The add-in contained in this package inserts section titles in a way that
that they are recognised by RStudio as sections (for details, see
https://support.rstudio.com/hc/en-us/articles/200484568-Code-Folding-and-Sections. One structure that is
recognised by RStudio as section is a line starting with a hash and ending
with four hashes. This structure is implemented with strcode
.
Hence when creating the summary, it might be desired to remove the right
hand hashes and spaces, which can be specified with the respective options
rm_rh_hashes
and rm_rh_spaces
.
insert_l_break
# the following separator is an example of a valid # separator and associated title # __________________________________________________ # this is a level 1 title #### ## . . . . . . . . . . . . . . . . . . . . . . . . . ## note that the title or the separator character (_, .) ## always starts at indention 4. ## Not run: ------------------------------------ # # Open a new .R file in RStudio, insert some code breaks # # using the Add-in of this package, save the file and run: # sum_str() # get a summary of the source editor. ## ---------------------------------------------