sum_str_helper: helper function for code summarisation return code summary...

Description Usage Arguments Details

View source: R/sum_str.R

Description

Function is called by sum_str() and returns summary of one code file.

Usage

1
2
3
sum_str_helper(path_in, dir_out, file_out, file_out_extension, rm_rh_hashes,
  rm_rh_spaces, rm_break_anchors, width, line_nr, granularity, last_sep, title,
  header)

Arguments

path_in

Either a path to a directory or to a single file. If it is a directory path, all files in that directory will be summarised. If it is a single file path, only the resepective file will be summarised. The default value uses the RStudio API to produce a summary of content from the source editor. This requires that the file is saved before sum_str is called.

dir_out

The directory to print the output to. "" implies the console.

file_out

A connection or character string naming the file to print to. If set to 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.

file_out_extension

A file extension for the file to be created.

rm_rh_hashes

Boolean value indicating whether or not to remove righthand hashes in section titles for the summary (see section Removing spaces and hashes).

rm_rh_spaces

Boolean value indicating whether or not to remove righthand spaces in section titles for the summary (see section Removing spaces and hashes).

rm_break_anchors

Boolean value indicating whether or not the anchors inserted in code separators should be removed for the summary.

width

The character width of the output. If NULL, it is set to the length of the longest separator title.

line_nr

A boolean value that indicates whether the line numbers should be printed along with the structure summary.

granularity

Indicates the lowest level of granularity that should be included in the summary.

last_sep

A boolean value indicating whether or not the separating lines of the highest granularity should be printed.

title

A boolean value indicating whether the reported summary should contain a title or not.

header

A boolean value indicating whether a column header should indicate the name of the columns (line, level, section).

Details

The core of the function is described best as follows: after a file was read in and stored in a vector *lines* whereas each element describes a line of code, the candidate lines (in the sense that they might be contained in the summary) were evaluated, their indices stored in *cand*. Next, various regex patterns are matched against *lines*. Then, after all tests were executed, the variable *remove* contains all indices that should be removed from *lines* before it is returned as the summary of the code file. Hence, applying setdiff(cand, remove) contains the subset of *lines* that we finally want to output.


XiaoliangJiang/IndependentStudy2017YW documentation built on May 29, 2019, 10:54 a.m.