Skip to contents

Builds a basic code counts report.

Usage

count_lines(con, verbose = FALSE)

Arguments

con

a connection object or a character string (passed to readLines).

verbose

a logical (FALSE by default) if counts should be printed to the console.

Value

a named vector.

Details

The report will contain the following information:

  • total

  • code

  • comment

  • documentation

  • spacing

Code lines ending with a comment are counted as code lines (hence ignored from comments).

See also

Examples

infile <- tempfile()

lines <- "#' This\n#'\n\n# comment\np <- 1\n\nif(p==1) print(p)\n"

writeLines(lines, infile)
count_lines(infile)
#>   total    code comment     doc spacing 
#>       8       3       1       1       3