You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

5.2 KiB

---
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-"
)
```

[![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

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.

## 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

## Usage

```{r eval=FALSE}
devtools::install_github("hrbrmstr/cloc")
```

```{r echo=FALSE, message=FALSE, warning=FALSE, error=FALSE}
options(width=120)
```

```{r message=FALSE, warning=FALSE, error=FALSE}
library(cloc)
library(tibble)

# current verison
packageVersion("cloc")
```

Basic usage

```{r message=FALSE, warning=FALSE, error=FALSE}
# by dir
cloc(system.file("extdata", package="cloc"))

# by file
cloc(system.file("extdata", "qrencoder.cpp", package="cloc"))

# from a url
cloc("https://rud.is/dl/cloc-1.74.tar.gz")
```

Custom CRAN package counter:

```{r message=FALSE, warning=FALSE, error=FALSE}
cloc_cran(c("archdata", "hrbrthemes", "iptools", "dplyr"))
```

git tree

```{r message=FALSE, warning=FALSE, error=FALSE, eval=FALSE}
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 message=FALSE, warning=FALSE, error=FALSE, eval=FALSE}
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 message=FALSE, warning=FALSE, error=FALSE}
cloc_git("git://github.com/maelle/convertagd.git")
```

Detailed results by file

```{r message=FALSE, warning=FALSE, error=FALSE}
# whole dir
str(cloc_by_file(system.file("extdata", package="cloc")))

# single file
str(cloc_by_file(system.file("extdata", "qrencoder.cpp", package="cloc")))
```

Recognized languages

```{r message=FALSE, warning=FALSE, error=FALSE}
cloc_recognized_languages()
```

Strip comments and whitespace from individual source files

```{r message=FALSE, warning=FALSE, error=FALSE}
cat(
cloc_remove_comments("https://raw.githubusercontent.com/maelle/convertagd/master/README.Rmd")
)
```

## cloc Metrics

```{r echo=FALSE}
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.