Skip to contents

Counting by file

scc_by_file() expands results to one row per source file, adding filename, location, and logical flags for generated and minified files.

rlang_by_file <- scc_by_file(rlang_path) 
str(rlang_by_file)
#> tibble [371 × 13] (S3: tbl_df/tbl/data.frame)
#>  $ language           : chr [1:371] "R" "R" "R" "R" ...
#>  $ filename           : chr [1:371] "standalone-types-check.R" "operators.R" "standalone-lazyeval.R" "eval-tidy.R" ...
#>  $ location           : chr [1:371] "/tmp/RtmpcdnHP1/rlang-1.1.6/R/standalone-types-check.R" "/tmp/RtmpcdnHP1/rlang-1.1.6/R/operators.R" "/tmp/RtmpcdnHP1/rlang-1.1.6/R/standalone-lazyeval.R" "/tmp/RtmpcdnHP1/rlang-1.1.6/R/eval-tidy.R" ...
#>  $ lines              : int [1:371] 591 93 112 605 93 405 256 430 144 7 ...
#>  $ code               : int [1:371] 483 29 89 191 12 213 139 240 111 4 ...
#>  $ comments           : int [1:371] 61 60 12 394 78 147 93 146 11 1 ...
#>  $ blanks             : int [1:371] 47 4 11 20 3 45 24 44 22 2 ...
#>  $ complexity         : int [1:371] 72 9 15 16 0 61 10 47 35 0 ...
#>  $ weighted_complexity: num [1:371] 14.91 31.03 16.85 8.38 0 ...
#>  $ bytes              : int [1:371] 10410 2538 2285 19617 3029 11966 6411 12193 3627 135 ...
#>  $ uloc               : int [1:371] 194 68 83 387 66 266 158 275 104 6 ...
#>  $ generated          : logi [1:371] FALSE FALSE FALSE FALSE FALSE FALSE ...
#>  $ minified           : logi [1:371] FALSE FALSE FALSE FALSE FALSE FALSE ...

Let’s take a look at this by complexity, and drop location, bytes, generated, and minified.

rlang_by_file_cm <- rlang_by_file[ , c("language", "filename", "lines", 
                                        "blanks", "comments", "uloc", 
                                        "complexity", "weighted_complexity")]
rlang_by_file_cm[order(rlang_by_file_cm$complexity, decreasing = TRUE), ] |> 
  head(10) |> 
  gt::gt() |> 
  gt::tab_header(
    title = "Top 10 Complex Files", 
    subtitle = "by complexity", 
    preheader = "rlang package")
Top 10 Complex Files
by complexity
language filename lines blanks comments uloc complexity weighted_complexity
C Header xxhash.h 4766 520 1588 2888 474 17.83296
R cnd-abort.R 1561 141 729 1023 152 21.99711
C parse.c 472 36 1 259 140 32.18391
R trace.R 1170 175 188 714 134 16.60471
R standalone-cli.R 572 49 172 395 131 37.32194
C dots.c 1143 175 24 680 129 13.66525
C exported.c 1096 165 59 606 112 12.84404
R deparse.R 1092 159 114 605 111 13.55311
R standalone-vctrs.R 669 116 48 364 107 21.18812
R call.R 1061 75 550 694 92 21.10092

Filter to just the R source files and sort by complexity:

r_files <- scc_by_file(rlang_path, include_ext = "r")
r_files_sub <- r_files[, c("filename", "lines", "code", "comments", "blanks", "complexity")]
r_files_sub[order(r_files_sub$complexity, decreasing = TRUE), ] |> 
  head(10) |> 
  gt::gt() |> 
  gt::tab_header(
    title = "Top 10 Complex R Files", 
    subtitle = "rlang package", 
    preheader = "rlang package")
Top 10 Complex R Files
rlang package
filename lines code comments blanks complexity
cnd-abort.R 1561 691 729 141 152
trace.R 1170 807 188 175 134
standalone-cli.R 572 351 172 49 131
deparse.R 1092 819 114 159 111
standalone-vctrs.R 669 505 48 116 107
call.R 1061 436 550 75 92
standalone-types-check.R 591 483 61 47 72
standalone-obj-type.R 360 242 79 39 67
cnd-entrace.R 405 213 147 45 61
utils.R 372 302 11 59 59

For visualization of these per-file metrics, see the Visualization vignette.