Skip to contents

Get Code Composition Stats

Usage

code_line_stats(
  code_text,
  lang = c("R", "Python", "SPSS", "SAS", "Stata", "Mplus", "MATLAB")
)

Arguments

code_text

the code text for a single file

lang

the language (we only currently handle R, Python, SPSS, SAS, Stata, Mplus, MATLAB)

Value

list with items total_lines, comment_lines, code_lines, percent_comment, and (Python only) has_docstring

Examples

code_text <- c(
  "library(dplyr)",
  "",
  "# this line is a comment",
  "a <- 1"
)
code_line_stats(code_text, "R")
#> $total_lines
#> [1] 3
#> 
#> $comment_lines
#> [1] 1
#> 
#> $code_lines
#> [1] 2
#> 
#> $percent_comments
#> [1] 0.3333333
#> 
#> $has_docstring
#> [1] NA
#>