~hrbrmstr/cloc

cloc/R/cloc-pkg.R -rw-r--r-- 929 bytes
0350958fhrbrmstr Working on #10 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#' @keywords internal
cloc_pkg_addin <- function() {

  ctx <- rstudioapi::getActiveDocumentContext()

  if (!is.null(ctx)) {

    pkg_root <- rprojroot::find_package_root_file(path = ".")

    res <- cloc::cloc_pkg(pkg_root)
    res <- res[,-1] # we know what pkg we're in

    DT::datatable(
      data = res,
      options = list(pageLength = 20),
      colnames = c(
        "Lang",
        "# Files", "(%)",
        "LoC", "(%)",
        "Blank lines", "(%)",
        "# Lines", "(%)"
      ),
      caption = sprintf("Code Metrics For %s", basename(pkg_root)),
      style = "default"
    ) -> cloc_dt

    cloc_dt <- DT::formatPercentage(cloc_dt, 'file_count_pct', 2)
    cloc_dt <- DT::formatPercentage(cloc_dt, 'loc_pct', 2)
    cloc_dt <- DT::formatPercentage(cloc_dt, 'blank_line_pct', 2)
    cloc_dt <- DT::formatPercentage(cloc_dt, 'comment_line_pct', 2)

    htmltools::html_print(cloc_dt)

    print(res)

  }

}