R/lines_of_comments.R

Defines functions lines_of_comments

Documented in lines_of_comments

#' Lines of comments for a file
#' @description Calculate the total lines of comments for a file
#' @param file The file to calculate for - a file-path.
#'
#' @return The list with two entries - the documentation comments, and the actual
#' comments.
#' @export
lines_of_comments <- function( file )
{
  tokens <- sourcetools::tokenize_file(file)
  tokens <- tokens[ tokens$type == "comment","value"]

  return( list(
    documentation = length( grep( pattern = "^#'", x = tokens) ),
    comments = length( grep( pattern = "^#'", x = tokens, invert = TRUE) )
  ))
}
JSzitas/qa documentation built on Dec. 18, 2021, 12:28 a.m.