Browse Source

Working on #10

master
boB Rudis 4 years ago
parent
commit
0350958fb7
No known key found for this signature in database GPG Key ID: 1D7529BE14E2BBA9
  1. 7
      DESCRIPTION
  2. 9
      NEWS.md
  3. 42
      R/cloc-by-file.r
  4. 26
      R/cloc-recognized-languages.r
  5. 40
      R/cloc.R
  6. 34
      R/clock-pkg-src.R
  7. 28
      R/sloc-rm-comments.R
  8. 63
      README.Rmd
  9. 377
      README.md
  10. 2088
      inst/bin/cloc.pl
  11. 8
      man/cloc-package.Rd
  12. 11
      man/cloc_cran.Rd
  13. 11
      man/cloc_git.Rd
  14. 8
      tests/testthat/test-cloc.R

7
DESCRIPTION

@ -1,6 +1,7 @@
Package: cloc
Title: Count Lines of Code, Comments and Whitespace in Source Files and Archives
Version: 0.3.0
Version: 0.3.5
Date: 2020-08-21
Authors@R: c(
person("Bob", "Rudis", email = "bob@rud.is", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-5670-2640")),
@ -26,10 +27,10 @@ Imports:
processx
Encoding: UTF-8
Depends:
R (>= 3.2.0)
R (>= 3.6.0)
License: MIT + file LICENSE
LazyData: true
Suggests:
testthat,
covr
RoxygenNote: 6.1.1
RoxygenNote: 7.1.1

9
NEWS.md

@ -1,3 +1,8 @@
# cloc 0.3.5
- upgraded bundled clocl.pl to 1.86
- switched from `system()` to `processx::run()` package-wide to address #10
# cloc 0.3.0
- upgraded bundled cloc.pl to 1.80
@ -6,12 +11,12 @@
- included a custom `cloc.pl` script (`cloc` pending PR <https://github.com/AlDanial/cloc/pull/294>)
that adds support for R Markdown (Rmd) files. Only the lines of code between
the triple-backticks clode blocks are included. THe resultant "language" type is
the triple-backticks code blocks are included. THe resultant "language" type is
`Rmd` as the code blocks could be anything. The results will only be fully accurate for
R/Python-ish syntax languages (i.e. the ones supporting the basic `cloc` rules for
those languages) but they should be accurate enough for rough estimates for
other languages used in Rmd code blocks.
- URLs as sources work in more funtions now
- URLs as sources work in more functions now
- cloc_git() can now clone repo when using git:// URLs
- removed dplyr dependency
- created an RStudio addin to enable reducing the active Rmd document to just code (in a new document)

42
R/cloc-by-file.r

@ -31,23 +31,43 @@ cloc_by_file <- function(source, extract_with=NULL) {
stopifnot(file.exists(source))
# make the command line
sprintf(
"%s %s --quiet --by-file --csv %s",
perl,
c(
system.file("bin/cloc.pl", package = "cloc"),
"--quiet",
"--by-file",
"--csv",
source
) -> cmd
) -> args
# tack on the "--extract-with" value (if specified)
if (!is.null(extract_with)) cmd <- sprintf('%s --extract-with="%s"', cmd, extract_with)
if (!is.null(extract_with)) {
cmd <- c(args, sprintf('--extract-with="%s"', extract_with))
}
# run the perl script
dat <- system(cmd, intern = TRUE)
processx::run(
command = perl,
args = args
) -> res
dat <- res$stdout
# # make the command line
#
# sprintf(
# "%s %s --quiet --by-file --csv %s",
# perl,
# shQuote(system.file("bin/cloc.pl", package = "cloc")),
# source
# ) -> cmd
#
# # tack on the "--extract-with" value (if specified)
# if (!is.null(extract_with)) cmd <- sprintf('%s --extract-with="%s"', cmd, extract_with)
#
# # run the perl script
# dat <- system(cmd, intern = TRUE)
# nothing to count
if (length(dat) == 0) {
if (nzchar(dat) == 0) {
return(
data.frame(
source = basename(source),
@ -61,6 +81,8 @@ cloc_by_file <- function(source, extract_with=NULL) {
)
}
dat <- unlist(strsplit(dat, "\r?\n"))
# read in the output from the perl script
fil <- read.table(
text = paste(utils::tail(dat, -2), sep = "", collapse = "\n"),

26
R/cloc-recognized-languages.r

@ -36,14 +36,28 @@ cloc_recognized_languages <- function() {
)
}
sprintf(
"%s %s --show-lang",
perl,
c(
system.file("bin/cloc.pl", package = "cloc"),
source
) -> cmd
"--show-lang"
) -> args
dat <- system(cmd, intern = TRUE)
processx::run(
command = perl,
args = args
) -> res
dat <- res$stdout
dat <- unlist(strsplit(dat, "\r?\n"))
# sprintf(
# "%s %s --show-lang",
# perl,
# shQuote(system.file("bin/cloc.pl", package = "cloc")),
# source
# ) -> cmd
#
# dat <- system(cmd, intern = TRUE)
do.call(rbind.data.frame,
lapply(

40
R/cloc.R

@ -36,23 +36,41 @@ cloc <- function(source = ".", extract_with = NULL) {
stopifnot(file.exists(source))
# make the command line
sprintf(
"%s %s --quiet --csv %s",
perl,
c(
system.file("bin/cloc.pl", package = "cloc"),
"--quiet",
"--csv",
source
) -> cmd
) -> args
# tack on the "--extract-with" value (if specified)
if (!is.null(extract_with)) cmd <- sprintf('%s --extract-with="%s"', cmd, extract_with)
if (!is.null(extract_with)) {
cmd <- c(args, sprintf('--extract-with="%s"', extract_with))
}
processx::run(
command = perl,
args = args
) -> res
# run the perl script
dat <- system(cmd, intern = TRUE)
dat <- res$stdout
# make the command line
# sprintf(
# "%s %s --quiet --csv %s",
# perl,
# shQuote(system.file("bin/cloc.pl", package = "cloc")),
# source
# ) -> cmd
#
# # tack on the "--extract-with" value (if specified)
# if (!is.null(extract_with)) cmd <- sprintf('%s --extract-with="%s"', cmd, extract_with)
#
# # run the perl script
# dat <- system(cmd, intern = TRUE)
# nothing to count
if (length(dat) == 0) {
if (nzchar(dat) == 0) {
return(
data.frame(
source = basename(source),
@ -70,6 +88,8 @@ cloc <- function(source = ".", extract_with = NULL) {
)
}
dat <- unlist(strsplit(dat, "\r?\n"))
# read in the output from the perl script
fil <- read.table(
text = paste(utils::tail(dat, -2), sep = "", collapse = "\n"),

34
R/clock-pkg-src.R

@ -41,21 +41,39 @@ cloc_pkg <- function(source = ".", extract_with = NULL) {
# make the command line
sprintf(
"%s %s --exclude-ext=yml,md,Rproj --exclude-dir=.Rproj,.Rproj.user,.git,inst,man,docs,tools --quiet --csv %s",
perl,
c(
system.file("bin/cloc.pl", package = "cloc"),
"--exclude-ext=yml,md,Rproj",
"--exclude-dir=.Rproj,.Rproj.user,.git,inst,man,docs,tools",
"--quiet",
"--csv",
source
) -> cmd
) -> args
# tack on the "--extract-with" value (if specified)
if (!is.null(extract_with)) cmd <- sprintf('%s --extract-with="%s"', cmd, extract_with)
if (!is.null(extract_with)) {
cmd <- c(args, sprintf('--extract-with="%s"', extract_with))
}
processx::run(
command = perl,
args = args
) -> res
dat <- res$stdout
# sprintf(
# "%s %s --exclude-ext=yml,md,Rproj --exclude-dir=.Rproj,.Rproj.user,.git,inst,man,docs,tools --quiet --csv %s",
# perl,
# shQuote(system.file("bin/cloc.pl", package = "cloc")),
# source
# ) -> cmd
# run the perl script
dat <- system(cmd, intern = TRUE)
# dat <- system(cmd, intern = TRUE)
# nothing to count
if (length(dat) == 0) {
if (nzchar(dat) == 0) {
return(
data.frame(
source = basename(source),
@ -73,6 +91,8 @@ cloc_pkg <- function(source = ".", extract_with = NULL) {
)
}
dat <- unlist(strsplit(dat, "\r?\n"))
# read in the output from the perl script
fil <- read.table(
text = paste(utils::tail(dat, -2), sep = "", collapse = "\n"),

28
R/sloc-rm-comments.R

@ -27,13 +27,12 @@ cloc_remove_comments <- function(source_file) {
stopifnot(file.exists(source_file))
# make the command line
sprintf(
"%s %s --strip-comments=nc %s",
perl,
system.file("bin/cloc.pl", package = "cloc"),
source_file
) -> cmd
# sprintf(
# "%s %s --strip-comments=nc %s",
# perl,
# shQuote(system.file("bin/cloc.pl", package = "cloc")),
# source_file
# ) -> cmd
td <- tempdir()
curr_dir <- getwd()
@ -41,7 +40,20 @@ cloc_remove_comments <- function(source_file) {
setwd(td)
dat <- system(cmd, intern = TRUE)
c(
system.file("bin/cloc.pl", package = "cloc"),
"--strip-comments=nc",
source_file
) -> args
processx::run(
command = perl,
args = args
) -> res
dat <- res$stdout
# dat <- system(cmd, intern = TRUE)
paste0(
readLines(

63
README.Rmd

@ -3,63 +3,41 @@ output: rmarkdown::github_document
editor_options:
chunk_output_type: console
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "README-"
)
```{r pkg-knitr-opts, include=FALSE}
hrbrpkghelpr::global_opts()
```
[![Travis-CI Build Status](https://travis-ci.org/hrbrmstr/cloc.svg?branch=master)](https://travis-ci.org/hrbrmstr/cloc)
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/hrbrmstr/cloc?branch=master&svg=true)](https://ci.appveyor.com/project/hrbrmstr/cloc)
[![Coverage Status](https://img.shields.io/codecov/c/github/hrbrmstr/cloc/master.svg)](https://codecov.io/github/hrbrmstr/cloc?branch=master)
# cloc
Count Lines of Code, Comments and Whitespace in Source Files and Archives
## Description
```{r badges, results='asis', echo=FALSE, cache=FALSE}
hrbrpkghelpr::stinking_badges()
```
Counts blank lines, comment lines, and physical lines of source code in source
files/trees/archives. An R wrapper to the Perl `cloc` utility
<https://github.com/AlDanial/cloc> by @AlDanial.
```{r description, results='asis', echo=FALSE, cache=FALSE}
hrbrpkghelpr::yank_title_and_description()
```
## What's Inside The Tin
The following functions are implemented:
- `cloc`: Count lines of code, comments and whitespace in source files/archives
- `cloc_by_file`: Count lines of code, comments and whitespace in source files/archives by file
- `cloc_cran`: Count lines of code (etc) from source packages on CRAN
- `cloc_git`: Count lines of code, comments and whitespace in a git tree
- `cloc_remove_comments`: Strip comments and white space from a single source file
- `cloc_recognized_languages`: Return a data frame of 'cloc' recognized languages and associated extensions
- `cloc_call`: Call 'cloc.pl' directly with granular control over options
- `clock_pkg_md` : Run `cloc_pkg()` on active package and format it as a markdown table for knitting into reports
- `cloc_help`: See the command-line help
- `cloc_version`: Retrieve the version of the embedded perl script
- `cloc_os`: Ask the embedded perl script to detect the OS type
```{r ingredients, results='asis', echo=FALSE, cache=FALSE}
hrbrpkghelpr::describe_ingredients()
```
## Usage
## Installation
```{r eval=FALSE}
devtools::install_github("hrbrmstr/cloc")
```{r install-ex, results='asis', echo=FALSE, cache=FALSE}
hrbrpkghelpr::install_block()
```
```{r echo=FALSE, message=FALSE, warning=FALSE, error=FALSE}
options(width=120)
```
## Usage
```{r message=FALSE, warning=FALSE, error=FALSE}
```{r lib-ex}
library(cloc)
library(tibble)
library(tibble) # for printing
# current verison
# current version
packageVersion("cloc")
```
Basic usage
@ -143,5 +121,4 @@ cloc_pkg_md()
## Code of Conduct
Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md).
By participating in this project you agree to abide by its terms.
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.

377
README.md

@ -1,235 +1,240 @@
<!-- README.md is generated from README.Rmd. Please edit that file -->
[![Travis-CI Build
[![Project Status: Active – The project has reached a stable, usable
state and is being actively
developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active)
[![Signed
by](https://img.shields.io/badge/Keybase-Verified-brightgreen.svg)](https://keybase.io/hrbrmstr)
![Signed commit
%](https://img.shields.io/badge/Signed_Commits-74%25-lightgrey.svg)
[![Linux build
Status](https://travis-ci.org/hrbrmstr/cloc.svg?branch=master)](https://travis-ci.org/hrbrmstr/cloc)
[![AppVeyor Build
Status](https://ci.appveyor.com/api/projects/status/github/hrbrmstr/cloc?branch=master&svg=true)](https://ci.appveyor.com/project/hrbrmstr/cloc)
[![Windows build
status](https://ci.appveyor.com/api/projects/status/github/hrbrmstr/cloc?svg=true)](https://ci.appveyor.com/project/hrbrmstr/cloc)
[![Coverage
Status](https://img.shields.io/codecov/c/github/hrbrmstr/cloc/master.svg)](https://codecov.io/github/hrbrmstr/cloc?branch=master)
Status](https://codecov.io/gh/hrbrmstr/cloc/branch/master/graph/badge.svg)](https://codecov.io/gh/hrbrmstr/cloc)
![Minimal R
Version](https://img.shields.io/badge/R%3E%3D-3.6.0-blue.svg)
![License](https://img.shields.io/badge/License-MIT-blue.svg)
# cloc
cloc
====
Count Lines of Code, Comments and Whitespace in Source Files and
Archives
## Description
Description
-----------
Counts blank lines, comment lines, and physical lines of source code in
source files/trees/archives. An R wrapper to the Perl `cloc` utility
<https://github.com/AlDanial/cloc> by @AlDanial.
source files/trees/archives. An R wrapper to the ‘Perl’ command-line
utility
<a href="https://github.com/AlDanial/cloc" class="uri">https://github.com/AlDanial/cloc</a>.
## What’s Inside The Tin
What’s Inside The Tin
---------------------
The following functions are implemented:
- `cloc`: Count lines of code, comments and whitespace in source
files/archives
- `cloc_by_file`: Count lines of code, comments and whitespace in
- `cloc_by_file`: Count lines of code, comments and whitespace in
source files/archives by file
- `cloc_cran`: Count lines of code (etc) from source packages on CRAN
- `cloc_git`: Count lines of code, comments and whitespace in a git
- `cloc_call`: Call cloc.pl directly with granular control over
options
- `cloc_cran`: Count lines of code (etc) from source packages on CRAN
- `cloc_git`: Count lines of code, comments and whitespace in a git
tree
- `cloc_remove_comments`: Strip comments and white space from a single
- `cloc_pkg_md`: Run cloc\_pkg() on active package and format it as a
markdown table for knitting into reports
- `cloc_pkg`: Count lines of code, comments and whitespace in a
package
- `cloc_recognized_languages`: Return a data frame of cloc recognized
languages and associated extensions
- `cloc_remove_comments`: Strip comments and white space from a single
source file
- `cloc_recognized_languages`: Return a data frame of ‘cloc’
recognized languages and associated extensions
- `cloc_call`: Call ‘cloc.pl’ directly with granular control over
options
- `clock_pkg_md` : Run `cloc_pkg()` on active package and format it as
a markdown table for knitting into reports
- `cloc_help`: See the command-line help
- `cloc_version`: Retrieve the version of the embedded perl script
- `cloc_os`: Ask the embedded perl script to detect the OS type
## Usage
Installation
------------
``` r
devtools::install_github("hrbrmstr/cloc")
```
install.packages("cloc", repos = c("https://cinc.rud.is", "https://cloud.r-project.org/"))
# or
remotes::install_git("https://git.rud.is/hrbrmstr/cloc.git")
# or
remotes::install_git("https://git.sr.ht/~hrbrmstr/cloc")
# or
remotes::install_gitlab("hrbrmstr/cloc")
# or
remotes::install_bitbucket("hrbrmstr/cloc")
# or
remotes::install_github("hrbrmstr/cloc")
``` r
library(cloc)
library(tibble)
NOTE: To use the ‘remotes’ install options you will need to have the
[{remotes} package](https://github.com/r-lib/remotes) installed.
# current verison
packageVersion("cloc")
#> [1] '0.3.0'
```
Usage
-----
library(cloc)
library(tibble) # for printing
# current version
packageVersion("cloc")
## [1] '0.3.5'
Basic usage
``` r
# by dir
cloc(system.file("extdata", package="cloc"))
#> # A tibble: 2 x 10
#> source language file_count file_count_pct loc loc_pct blank_lines blank_line_pct comment_lines comment_line_pct
#> <chr> <chr> <int> <dbl> <int> <dbl> <int> <dbl> <int> <dbl>
#> 1 extdata C++ 1 0.5 142 0.507 41 0.631 63 0.470
#> 2 extdata R 1 0.5 138 0.493 24 0.369 71 0.530
# by file
cloc(system.file("extdata", "qrencoder.cpp", package="cloc"))
#> # A tibble: 1 x 10
#> source language file_count file_count_pct loc loc_pct blank_lines blank_line_pct comment_lines comment_line_pct
#> <chr> <chr> <int> <dbl> <int> <dbl> <int> <dbl> <int> <dbl>
#> 1 qrencoder.… C++ 1 1 142 1 41 1 63 1
# from a url
cloc("https://rud.is/dl/cloc-1.74.tar.gz")
#> # A tibble: 93 x 10
#> source language file_count file_count_pct loc loc_pct blank_lines blank_line_pct comment_lines comment_line_pct
#> <chr> <chr> <int> <dbl> <int> <dbl> <int> <dbl> <int> <dbl>
#> 1 cloc-1.7… Perl 5 0.0180 19712 0.598 1353 0.420 2430 0.443
#> 2 cloc-1.7… YAML 141 0.507 2887 0.0876 1 0.000311 141 0.0257
#> 3 cloc-1.7… Markdown 1 0.00360 2195 0.0666 226 0.0702 26 0.00474
#> 4 cloc-1.7… ANTLR Gr… 2 0.00719 1012 0.0307 200 0.0621 59 0.0108
#> 5 cloc-1.7… R 3 0.0108 698 0.0212 95 0.0295 312 0.0569
#> 6 cloc-1.7… C/C++ He… 1 0.00360 617 0.0187 191 0.0593 780 0.142
#> 7 cloc-1.7… C++ 4 0.0144 570 0.0173 132 0.0410 173 0.0315
#> 8 cloc-1.7… Forth 2 0.00719 529 0.0160 17 0.00528 84 0.0153
#> 9 cloc-1.7… TypeScri… 3 0.0108 410 0.0124 52 0.0162 39 0.00711
#> 10 cloc-1.7… Logtalk 1 0.00360 368 0.0112 59 0.0183 57 0.0104
#> # … with 83 more rows
```
# by dir
cloc(system.file("extdata", package="cloc"))
## # A tibble: 3 x 10
## source language file_count file_count_pct loc loc_pct blank_lines blank_line_pct comment_lines comment_line_pct
## <chr> <chr> <int> <dbl> <int> <dbl> <int> <dbl> <int> <dbl>
## 1 extdata C++ 1 0.25 142 0.254 41 0.315 63 0.235
## 2 extdata R 1 0.25 138 0.246 24 0.185 71 0.265
## 3 extdata SUM 2 0.5 280 0.5 65 0.5 134 0.5
# by file
cloc(system.file("extdata", "qrencoder.cpp", package="cloc"))
## # A tibble: 2 x 10
## source language file_count file_count_pct loc loc_pct blank_lines blank_line_pct comment_lines comment_line_pct
## <chr> <chr> <int> <dbl> <int> <dbl> <int> <dbl> <int> <dbl>
## 1 qrencoder.… C++ 1 0.5 142 0.5 41 0.5 63 0.5
## 2 qrencoder.… SUM 1 0.5 142 0.5 41 0.5 63 0.5
# from a url
cloc("https://rud.is/dl/cloc-1.74.tar.gz")
## # A tibble: 93 x 10
## source language file_count file_count_pct loc loc_pct blank_lines blank_line_pct comment_lines comment_line_pct
## <chr> <chr> <int> <dbl> <int> <dbl> <int> <dbl> <int> <dbl>
## 1 cloc-1.7… Perl 5 0.00903 19712 0.299 1353 0.211 2430 0.222
## 2 cloc-1.7… YAML 141 0.255 2887 0.0438 1 0.000156 141 0.0129
## 3 cloc-1.7… Markdown 1 0.00181 2195 0.0333 226 0.0352 26 0.00237
## 4 cloc-1.7… ANTLR Gr… 2 0.00361 1012 0.0154 200 0.0312 59 0.00538
## 5 cloc-1.7… R 3 0.00542 698 0.0106 95 0.0148 312 0.0285
## 6 cloc-1.7… C/C++ He… 1 0.00181 617 0.00937 191 0.0298 780 0.0712
## 7 cloc-1.7… C++ 4 0.00722 570 0.00865 132 0.0206 173 0.0158
## 8 cloc-1.7… Forth 2 0.00361 529 0.00803 17 0.00265 84 0.00766
## 9 cloc-1.7… TypeScri… 3 0.00542 410 0.00622 52 0.00810 39 0.00356
## 10 cloc-1.7… Logtalk 1 0.00181 368 0.00559 59 0.00919 57 0.00520
## # … with 83 more rows
Custom CRAN package counter:
``` r
cloc_cran(c("archdata", "hrbrthemes", "iptools", "dplyr"))
#> # A tibble: 19 x 11
#> source language file_count file_count_pct loc loc_pct blank_lines blank_line_pct comment_lines comment_line_pct
#> <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 archd… <NA> 0 0 0 0. 0 0 0 0
#> 2 hrbrt… R 21 0.7 1094 6.63e-1 215 0.560 584 0.832
#> 3 hrbrt… HTML 2 0.0667 366 2.22e-1 48 0.125 2 0.00285
#> 4 hrbrt… CSS 1 0.0333 113 6.85e-2 27 0.0703 0 0
#> 5 hrbrt… Rmd 3 0.1 35 2.12e-2 78 0.203 116 0.165
#> 6 hrbrt… Markdown 1 0.0333 33 2.00e-2 16 0.0417 0 0
#> 7 hrbrt… YAML 2 0.0667 8 4.85e-3 0 0 0 0
#> 8 iptoo… C++ 4 0.138 846 4.21e-1 167 0.400 375 0.286
#> 9 iptoo… HTML 2 0.0690 633 3.15e-1 54 0.129 2 0.00153
#> 10 iptoo… R 20 0.690 444 2.21e-1 133 0.319 638 0.487
#> 11 iptoo… Rmd 2 0.0690 48 2.39e-2 33 0.0791 72 0.0550
#> 12 iptoo… C/C++ H… 1 0.0345 37 1.84e-2 30 0.0719 223 0.170
#> 13 dplyr… R 171 0.552 14999 4.76e-1 3127 0.425 4957 0.685
#> 14 dplyr… C/C++ H… 101 0.326 6661 2.11e-1 1754 0.238 483 0.0668
#> 15 dplyr… C++ 23 0.0742 4706 1.49e-1 954 0.130 437 0.0604
#> 16 dplyr… HTML 5 0.0161 3206 1.02e-1 140 0.0190 5 0.000691
#> 17 dplyr… Markdown 2 0.00645 1479 4.69e-2 708 0.0962 0 0
#> 18 dplyr… Rmd 7 0.0226 462 1.46e-2 667 0.0907 1350 0.187
#> 19 dplyr… C 1 0.00323 30 9.51e-4 7 0.000951 0 0
#> # … with 1 more variable: pkg <chr>
```
cloc_cran(c("archdata", "hrbrthemes", "iptools", "dplyr"))
## # A tibble: 23 x 11
## source language file_count file_count_pct loc loc_pct blank_lines blank_line_pct comment_lines comment_line_pct
## <chr> <chr> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 archd… <NA> 0 0 0 0 0 0 0 0
## 2 hrbrt… R 23 0.338 1615 0.345 308 0.314 827 0.437
## 3 hrbrt… HTML 2 0.0294 378 0.0807 53 0.0541 3 0.00159
## 4 hrbrt… SVG 2 0.0294 150 0.0320 0 0 0 0
## 5 hrbrt… CSS 1 0.0147 113 0.0241 27 0.0276 0 0
## 6 hrbrt… Markdown 1 0.0147 44 0.00939 24 0.0245 0 0
## 7 hrbrt… Rmd 3 0.0441 35 0.00747 78 0.0796 116 0.0613
## 8 hrbrt… YAML 2 0.0294 8 0.00171 0 0 0 0
## 9 hrbrt… SUM 34 0.5 2343 0.5 490 0.5 946 0.5
## 10 iptoo… C++ 4 0.0690 846 0.211 167 0.200 375 0.143
## # … with 13 more rows, and 1 more variable: pkg <chr>
git tree
``` r
cloc_git("~/packages/cloc")
## source language file_count file_count_pct loc loc_pct blank_lines blank_line_pct comment_lines comment_line_pct
## 1 cloc Perl 1 0.1111111 10059 0.9867569158 787 0.910879630 1292 0.9570370370
## 2 cloc Markdown 2 0.2222222 60 0.0058858152 31 0.035879630 0 0.0000000000
## 3 cloc R 4 0.4444444 52 0.0051010398 22 0.025462963 25 0.0185185185
## 4 cloc Rmd 1 0.1111111 13 0.0012752600 21 0.024305556 32 0.0237037037
## 5 cloc YAML 1 0.1111111 10 0.0009809692 3 0.003472222 1 0.0007407407
```
cloc_git("~/packages/cloc")
## source language file_count file_count_pct loc loc_pct blank_lines blank_line_pct comment_lines comment_line_pct
## 1 cloc Perl 1 0.1111111 10059 0.9867569158 787 0.910879630 1292 0.9570370370
## 2 cloc Markdown 2 0.2222222 60 0.0058858152 31 0.035879630 0 0.0000000000
## 3 cloc R 4 0.4444444 52 0.0051010398 22 0.025462963 25 0.0185185185
## 4 cloc Rmd 1 0.1111111 13 0.0012752600 21 0.024305556 32 0.0237037037
## 5 cloc YAML 1 0.1111111 10 0.0009809692 3 0.003472222 1 0.0007407407
git tree (with specific commit)
``` r
cloc_git("~/packages/cloc", "3643cd09d4b951b1b35d32dffe35985dfe7756c4")
## source language file_count file_count_pct loc loc_pct blank_lines blank_line_pct comment_lines comment_line_pct
## 1 cloc Perl 1 0.1111111 10059 0.9867569158 787 0.910879630 1292 0.9570370370
## 2 cloc Markdown 2 0.2222222 60 0.0058858152 31 0.035879630 0 0.0000000000
## 3 cloc R 4 0.4444444 52 0.0051010398 22 0.025462963 25 0.0185185185
## 4 cloc Rmd 1 0.1111111 13 0.0012752600 21 0.024305556 32 0.0237037037
## 5 cloc YAML 1 0.1111111 10 0.0009809692 3 0.003472222 1 0.0007407407
```
cloc_git("~/packages/cloc", "3643cd09d4b951b1b35d32dffe35985dfe7756c4")
## source language file_count file_count_pct loc loc_pct blank_lines blank_line_pct comment_lines comment_line_pct
## 1 cloc Perl 1 0.1111111 10059 0.9867569158 787 0.910879630 1292 0.9570370370
## 2 cloc Markdown 2 0.2222222 60 0.0058858152 31 0.035879630 0 0.0000000000
## 3 cloc R 4 0.4444444 52 0.0051010398 22 0.025462963 25 0.0185185185
## 4 cloc Rmd 1 0.1111111 13 0.0012752600 21 0.024305556 32 0.0237037037
## 5 cloc YAML 1 0.1111111 10 0.0009809692 3 0.003472222 1 0.0007407407
remote git tree
``` r
cloc_git("git://github.com/maelle/convertagd.git")
#> # A tibble: 4 x 10
#> source language file_count file_count_pct loc loc_pct blank_lines blank_line_pct comment_lines comment_line_pct
#> <chr> <chr> <int> <dbl> <int> <dbl> <int> <dbl> <int> <dbl>
#> 1 convertagd… R 7 0.583 249 0.659 70 0.56 68 0.667
#> 2 convertagd… Markdown 2 0.167 77 0.204 23 0.184 0 0
#> 3 convertagd… YAML 2 0.167 42 0.111 16 0.128 4 0.0392
#> 4 convertagd… Rmd 1 0.0833 10 0.0265 16 0.128 30 0.294
```
cloc_git("git://github.com/maelle/convertagd.git")
## # A tibble: 5 x 10
## source language file_count file_count_pct loc loc_pct blank_lines blank_line_pct comment_lines comment_line_pct
## <chr> <chr> <int> <dbl> <int> <dbl> <int> <dbl> <int> <dbl>
## 1 convertagd… R 7 0.292 249 0.329 70 0.28 68 0.333
## 2 convertagd… Markdown 2 0.0833 77 0.102 23 0.092 0 0
## 3 convertagd… YAML 2 0.0833 42 0.0556 16 0.064 4 0.0196
## 4 convertagd… Rmd 1 0.0417 10 0.0132 16 0.064 30 0.147
## 5 convertagd… SUM 12 0.5 378 0.5 125 0.5 102 0.5
Detailed results by file
``` r
# whole dir
str(cloc_by_file(system.file("extdata", package="cloc")))
#> Classes 'tbl_df', 'tbl' and 'data.frame': 2 obs. of 6 variables:
#> $ source : chr "extdata" "extdata"
#> $ filename : chr "/Library/Frameworks/R.framework/Versions/3.5/Resources/library/cloc/extdata/qrencoder.cpp" "/Library/Frameworks/R.framework/Versions/3.5/Resources/library/cloc/extdata/dbi.r"
#> $ language : chr "C++" "R"
#> $ loc : int 142 138
#> $ blank_lines : int 41 24
#> $ comment_lines: int 63 71
# single file
str(cloc_by_file(system.file("extdata", "qrencoder.cpp", package="cloc")))
#> Classes 'tbl_df', 'tbl' and 'data.frame': 1 obs. of 6 variables:
#> $ source : chr "qrencoder.cpp"
#> $ filename : chr "/Library/Frameworks/R.framework/Versions/3.5/Resources/library/cloc/extdata/qrencoder.cpp"
#> $ language : chr "C++"
#> $ loc : int 142
#> $ blank_lines : int 41
#> $ comment_lines: int 63
```
# whole dir
str(cloc_by_file(system.file("extdata", package="cloc")))
## tibble [3 × 6] (S3: tbl_df/tbl/data.frame)
## $ source : chr [1:3] "extdata" "extdata" "extdata"
## $ filename : chr [1:3] "/Library/Frameworks/R.framework/Versions/4.0/Resources/library/cloc/extdata/qrencoder.cpp" "/Library/Frameworks/R.framework/Versions/4.0/Resources/library/cloc/extdata/dbi.r" ""
## $ language : chr [1:3] "C++" "R" "SUM"
## $ loc : int [1:3] 142 138 280
## $ blank_lines : int [1:3] 41 24 65
## $ comment_lines: int [1:3] 63 71 134
# single file
str(cloc_by_file(system.file("extdata", "qrencoder.cpp", package="cloc")))
## tibble [2 × 6] (S3: tbl_df/tbl/data.frame)
## $ source : chr [1:2] "qrencoder.cpp" "qrencoder.cpp"
## $ filename : chr [1:2] "/Library/Frameworks/R.framework/Versions/4.0/Resources/library/cloc/extdata/qrencoder.cpp" ""
## $ language : chr [1:2] "C++" "SUM"
## $ loc : int [1:2] 142 142
## $ blank_lines : int [1:2] 41 41
## $ comment_lines: int [1:2] 63 63
Recognized languages
``` r
cloc_recognized_languages()
#> # A tibble: 242 x 2
#> lang extensions
#> <chr> <chr>
#> 1 ABAP abap
#> 2 ActionScript as
#> 3 Ada ada, adb, ads, pad
#> 4 ADSO/IDSM adso
#> 5 Agda agda, lagda
#> 6 AMPLE ample, dofile, startup
#> 7 Ant build.xml, build.xml
#> 8 ANTLR Grammar g, g4
#> 9 Apex Trigger trigger
#> 10 Arduino Sketch ino, pde
#> # … with 232 more rows
```
cloc_recognized_languages()
## # A tibble: 262 x 2
## lang extensions
## <chr> <chr>
## 1 ABAP abap
## 2 ActionScript as
## 3 Ada ada, adb, ads, pad
## 4 ADSO/IDSM adso
## 5 Agda agda, lagda
## 6 AMPLE ample, dofile, startup
## 7 Ant build.xml, build.xml
## 8 ANTLR Grammar g, g4
## 9 Apex Class cls
## 10 Apex Trigger trigger
## # … with 252 more rows
Strip comments and whitespace from individual source files
``` r
cat(
cloc_remove_comments("https://raw.githubusercontent.com/maelle/convertagd/master/README.Rmd")
)
#> library("knitr")
#> library("devtools")
#> install_github("masalmon/convertagd")
#> library("convertagd")
#> file <- system.file("extdata", "dummyCHAI.agd", package = "convertagd")
#> testRes <- read_agd(file, tz = "GMT")
#> kable(testRes[["settings"]])
#> kable(head(testRes[["raw.data"]]))
#> path_to_directory <- system.file("extdata", package = "convertagd")
#> batch_read_agd(path_to_directory, tz="GMT")
```
## cloc Metrics
cat(
cloc_remove_comments("https://raw.githubusercontent.com/maelle/convertagd/master/README.Rmd")
)
## library("knitr")
## library("devtools")
## install_github("masalmon/convertagd")
## library("convertagd")
## file <- system.file("extdata", "dummyCHAI.agd", package = "convertagd")
## testRes <- read_agd(file, tz = "GMT")
## kable(testRes[["settings"]])
## kable(head(testRes[["raw.data"]]))
## path_to_directory <- system.file("extdata", package = "convertagd")
## batch_read_agd(path_to_directory, tz="GMT")
cloc Metrics
------------
| Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) |
| :--- | -------: | ---: | --: | ---: | ----------: | ---: | -------: | ---: |
| R | 16 | 0.94 | 484 | 0.95 | 183 | 0.83 | 289 | 0.77 |
| Rmd | 1 | 0.06 | 24 | 0.05 | 38 | 0.17 | 85 | 0.23 |
|:-----|---------:|-----:|----:|-----:|------------:|-----:|---------:|-----:|
| R | 16 | 0.47 | 514 | 0.48 | 198 | 0.43 | 334 | 0.42 |
| Rmd | 1 | 0.03 | 22 | 0.02 | 34 | 0.07 | 68 | 0.08 |
| SUM | 17 | 0.50 | 536 | 0.50 | 232 | 0.50 | 402 | 0.50 |
clock Package Metrics for cloc
## Code of Conduct
Code of Conduct
---------------
Please note that this project is released with a [Contributor Code of
Conduct](CONDUCT.md). By participating in this project you agree to
abide by its terms.
Please note that this project is released with a Contributor Code of
Conduct. By participating in this project you agree to abide by its
terms.

2088
inst/bin/cloc.pl

File diff suppressed because it is too large

8
man/cloc-package.Rd

@ -11,7 +11,7 @@ files/trees/archives. An R wrapper to the Perl \code{cloc} utility
}
\section{How it works}{
\code{cloc}'s method of operation resembles \href{https://www.dwheeler.com/sloccount/}{SLOCCount}'s:
\code{cloc}'s method of operation resembles \href{https://www.dwheeler.com/sloccount/}{\code{SLOCCount}}'s:
First, create a list of files to consider. Next, attempt to determine whether or not
found files contain recognized computer language source code. Finally, for files
identified as source files, invoke language-specific routines to count the number of
@ -37,7 +37,7 @@ associates with programming languages. Files which match are classified as
containing source
code for that language. Each file without an extensions is opened
and its first line read to see if it is a Unix shell script
(anything that begins with \code{#!}). If it is shell script, the file is
(anything that begins with \verb{#!}). If it is shell script, the file is
classified by that scripting language (if the language is
recognized). If the file does not have a recognized extension or is
not a recognzied scripting language, the file is ignored.
@ -49,8 +49,8 @@ for known programming languages. For each of these files:
\item Remove blank lines, then count again (= L \emph{non-blank}).
\item Loop over the comment filters defined for this language. (For
example, C++ as two filters: (1) remove lines that start with
optional whitespace followed by \code{//} and (2) remove text between
\code{/*} and \code{*/}) Apply each filter to the code to remove comments.
optional whitespace followed by \verb{//} and (2) remove text between
\verb{/*} and \verb{*/}) Apply each filter to the code to remove comments.
Count the left over lines (= L \emph{code}).
\item Save the counts for this language:
\itemize{

11
man/cloc_cran.Rd

@ -4,16 +4,19 @@
\alias{cloc_cran}
\title{Count lines of code (etc) from source packages on CRAN}
\usage{
cloc_cran(pkgs, repos = getOption("repos"),
cloc_cran(
pkgs,
repos = getOption("repos"),
contrib_url = utils::contrib.url(repos, "source"),
.progress = interactive())
.progress = interactive()
)
}
\arguments{
\item{pkgs}{names of packages}
\item{repos}{character vector, the base URL(s) of the repositories to use,
i.e., the URL of the CRAN master such as "\code{https://cran.r-project.org}"
or its Statlib mirror, "\code{http://lib.stat.cmu.edu/R/CRAN}".}
i.e., the URL of the CRAN master such as "\verb{https://cran.r-project.org}"
or its Statlib mirror, "\verb{http://lib.stat.cmu.edu/R/CRAN}".}
\item{contrib_url}{URL(s) of the contrib sections of the repositories. Use
this argument only if your repository mirror is incomplete, e.g.,

11
man/cloc_git.Rd

@ -4,11 +4,16 @@
\alias{cloc_git}
\title{Count lines of code, comments and whitespace in a git tree}
\usage{
cloc_git(repo, commit = ".", branch = NULL, credentials = NULL,
progress = FALSE)
cloc_git(
repo,
commit = ".",
branch = NULL,
credentials = NULL,
progress = FALSE
)
}
\arguments{
\item{repo}{path to git repo; if \code{repo} is a URL like \code{git://}, it will be fetched into
\item{repo}{path to git repo; if \code{repo} is a URL like \verb{git://}, it will be fetched into
a temporary directory}
\item{commit}{"\code{.}" for the current source tree or the commit identifier for a specific commit}

8
tests/testthat/test-cloc.R

@ -1,9 +1,11 @@
context("cloc works (get it?")
context("cloc works (get it?)")
test_that("core bits are functioning as expected", {
langs <- cloc_recognized_languages()
expect_equal(langs$lang[4], "ADSO/IDSM")
expect_equal(cloc_version(), "1.80")
expect_equal(cloc_version(), "1.86")
expect_is(cloc_os(), "character")
@ -25,7 +27,7 @@ test_that("core bits are functioning as expected", {
bf <- cloc_by_file(system.file("extdata", "qrencoder.cpp", package="cloc"))
expect_equal(bf$loc, 142)
expect_equal(bf$loc[1], 142)
})

Loading…
Cancel
Save