~hrbrmstr/cloc

57cf38203176f85f5ab1a676f1963fea93be1235 — boB Rudis 6 years ago b671444
Removed R.utils dep
8 files changed, 23 insertions(+), 17 deletions(-)

M DESCRIPTION
M NAMESPACE
M R/cloc-by-file.r
M R/cloc-git.R
M R/cloc-package.r
M R/cloc.R
M R/sloc-rm-comments.R
A R/utils.R
M DESCRIPTION => DESCRIPTION +2 -4
@@ 1,13 1,12 @@
Package: cloc
Title: Count Lines of Code, Comments and Whitespace in Source Files and Archives
Version: 0.2.0
Version: 0.1.0
Authors@R: c(
    person("Bob", "Rudis", email = "bob@rud.is", role = c("aut", "cre"), 
           comment = c(ORCID = "0000-0001-5670-2640")),
    person("Al", "Danial", comment = "cloc perl script", role=c("aut")),
    person("Maƫlle", "Salmon", email = "maelle.salmon@yahoo.se", role = c("ctb")), 
    person("Chris", "Muir", email = "chrismuirrva@gmail.com", role = c("ctb")),
    person("Mark", "Padgham", email = "mark.padgham@email.com", role = c("ctb"))
    person("Chris", "Muir", email = "chrismuirrva@gmail.com", role = c("ctb"))
  )
Description: Counts blank lines, comment lines, and physical lines of source code 
    in source files/trees/archives. An R wrapper to the 'Perl' command-line utility 


@@ 15,7 14,6 @@ Description: Counts blank lines, comment lines, and physical lines of source cod
SystemRequirements: perl
Copyright: file inst/COPYRIGHTS
Imports:
    R.utils,
    utils, 
    dplyr,
    processx

M NAMESPACE => NAMESPACE +0 -1
@@ 10,7 10,6 @@ export(cloc_os)
export(cloc_remove_comments)
export(cloc_reognized_languages)
export(cloc_version)
importFrom(R.utils,isUrl)
importFrom(dplyr,bind_rows)
importFrom(dplyr,data_frame)
importFrom(dplyr,progress_estimated)

M R/cloc-by-file.r => R/cloc-by-file.r +2 -2
@@ 25,9 25,9 @@ cloc_by_file <- function(source, extract_with=NULL) {
      )
  }

  is_url <- R.utils::isUrl(source)
  tis_url <- is_url(source)

  if (is_url) { # download the source if a URL was specified
  if (tis_url) { # download the source if a URL was specified
    dir <- tempdir()
    utils::download.file(source, file.path(dir, basename(source)), method = "curl", quiet = TRUE)
    source <- file.path(dir, basename(source))

M R/cloc-git.R => R/cloc-git.R +7 -7
@@ 1,14 1,14 @@
#' Count lines of code, comments and whitespace in a git tree
#'
#' @md
#' @param repo_dir path to git repo
#' @param repo path to git repo
#' @param commit "`.`" for the current source tree or the commit identifier for a specific commit
#' @return tibble
#' @export
#' @examples \dontrun{
#' cloc_git("~/packages/cloc", "3643cd09d4b951b1b35d32dffe35985dfe7756c4")
#' }
cloc_git <- function(repo_dir, commit=".") {
cloc_git <- function(repo, commit=".") {

  perl <- Sys.which("perl")



@@ 19,15 19,15 @@ cloc_git <- function(repo_dir, commit=".") {
      )
  }

  repo_dir <- path.expand(repo_dir)
  repo <- path.expand(repo)

  stopifnot(file.exists(repo_dir))
  stopifnot(file.exists(repo))

  # make the command line

  curr_dir <- getwd()

  setwd(repo_dir)
  setwd(repo)
  on.exit(setwd(curr_dir), add=TRUE)

  x <- processx::run(


@@ 48,7 48,7 @@ cloc_git <- function(repo_dir, commit=".") {
  if (length(dat) == 0) {
    return(
      data.frame(
        source = basename(repo_dir),
        source = basename(repo),
        language = NA_character_,
        file_count = 0,
        file_count_pct = 0,


@@ 71,7 71,7 @@ cloc_git <- function(repo_dir, commit=".") {
  )

  # calculate percentages
  fil$source <- basename(repo_dir)
  fil$source <- basename(repo)
  fil$file_count_pct <- fil$file_count / sum(fil$file_count)
  fil$blank_line_pct <- fil$blank_lines / sum(fil$blank_lines)
  fil$comment_line_pct <- fil$comment_lines / sum(fil$comment_lines)

M R/cloc-package.r => R/cloc-package.r +0 -1
@@ 54,7 54,6 @@
#' @name cloc-package
#' @docType package
#' @author Bob Rudis (bob@@rud.is)
#' @importFrom R.utils isUrl
#' @importFrom utils read.table contrib.url download.file download.packages tail
#' @importFrom dplyr bind_rows progress_estimated data_frame
#' @importFrom processx run

M R/cloc.R => R/cloc.R +2 -2
@@ 30,9 30,9 @@ cloc <- function(source = ".", extract_with = NULL) {
      )
  }

  is_url <- R.utils::isUrl(source)
  tis_url <- is_url(source)

  if (is_url) { # download the source if a URL was specified
  if (tis_url) { # download the source if a URL was specified
    dir <- tempdir()
    utils::download.file(source, file.path(dir, basename(source)), method = "curl", quiet = TRUE)
    source <- file.path(dir, basename(source))

M R/sloc-rm-comments.R => R/sloc-rm-comments.R +9 -0
@@ 19,6 19,15 @@ cloc_remove_comments <- function(source_file) {
      )
  }

  tis_url <- is_url(source_file)

  if (tis_url) { # download the source_file if a URL was specified
    dir <- tempdir()
    utils::download.file(source_file, file.path(dir, basename(source_file)), method = "curl", quiet = TRUE)
    source_file <- file.path(dir, basename(source_file))
    on.exit(unlink(source_file), add = TRUE)
  }

  source_file <- path.expand(source_file)

  stopifnot(file.exists(source_file))

A R/utils.R => R/utils.R +1 -0
@@ 0,0 1,1 @@
is_url <- function (path) { grepl("^(http|ftp)s?://", path) }