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.
 
 

3.0 KiB

---
output: rmarkdown::github_document
---

<!-- 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_reognized_languages`: Return a data frame of 'cloc' recognized languages and associated extensions

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

# 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", "App.java", 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 (with specific commit)

```{r message=FALSE, warning=FALSE, error=FALSE}
cloc_git("~/packages/cloc", "3643cd09d4b951b1b35d32dffe35985dfe7756c4")
```

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", "App.java", package="cloc")))
```

Recognized languages

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

Strip comments and whitespace from individual source files

```{r message=FALSE, warning=FALSE, error=FALSE}
cat(
cloc_remove_comments(system.file("extdata", "qrencoder.cpp", package="cloc"))
)
```

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