18 changed files with 10838 additions and 4 deletions
@ -1,2 +1,7 @@ |
|||
^.*\.Rproj$ |
|||
^\.Rproj\.user$ |
|||
^README\.Rmd$ |
|||
^README-.*\.png$ |
|||
^\.travis\.yml$ |
|||
^CONDUCT\.md$ |
|||
^README\.md$ |
|||
|
@ -0,0 +1,14 @@ |
|||
# Sample .travis.yml for R projects |
|||
|
|||
language: r |
|||
warnings_are_errors: true |
|||
sudo: required |
|||
|
|||
env: |
|||
global: |
|||
- CRAN: http://cran.rstudio.com |
|||
|
|||
notifications: |
|||
email: |
|||
on_success: change |
|||
on_failure: change |
@ -0,0 +1,25 @@ |
|||
# Contributor Code of Conduct |
|||
|
|||
As contributors and maintainers of this project, we pledge to respect all people who |
|||
contribute through reporting issues, posting feature requests, updating documentation, |
|||
submitting pull requests or patches, and other activities. |
|||
|
|||
We are committed to making participation in this project a harassment-free experience for |
|||
everyone, regardless of level of experience, gender, gender identity and expression, |
|||
sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion. |
|||
|
|||
Examples of unacceptable behavior by participants include the use of sexual language or |
|||
imagery, derogatory comments or personal attacks, trolling, public or private harassment, |
|||
insults, or other unprofessional conduct. |
|||
|
|||
Project maintainers have the right and responsibility to remove, edit, or reject comments, |
|||
commits, code, wiki edits, issues, and other contributions that are not aligned to this |
|||
Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed |
|||
from the project team. |
|||
|
|||
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by |
|||
opening an issue or contacting one or more of the project maintainers. |
|||
|
|||
This Code of Conduct is adapted from the Contributor Covenant |
|||
(http:contributor-covenant.org), version 1.0.0, available at |
|||
http://contributor-covenant.org/version/1/0/0/ |
@ -1,8 +1,10 @@ |
|||
Package: cloc |
|||
Title: What the Package Does (one line, title case) |
|||
Title: Count Lines of Code, Comments and Whitespace in Source Files and Archives |
|||
Version: 0.0.0.9000 |
|||
Authors@R: c(person("Bob", "Rudis", email = "bob@rudis.net", role = c("aut", "cre"))) |
|||
Description: What the package does (one paragraph). |
|||
Depends: R (>= 3.2.1) |
|||
Description: Count lines of code! |
|||
Imports: R.utils, utils, dplyr, pbapply |
|||
Depends: R (>= 3.2.0) |
|||
License: MIT + file LICENSE |
|||
LazyData: true |
|||
Suggests: testthat |
|||
|
@ -1 +1,10 @@ |
|||
exportPattern("^[^\\.]") |
|||
# Generated by roxygen2 (4.1.1): do not edit by hand |
|||
|
|||
export(cloc) |
|||
export(cloc_cran) |
|||
importFrom(R.utils,isUrl) |
|||
importFrom(dplyr,bind_rows) |
|||
importFrom(dplyr,rbind_list) |
|||
importFrom(dplyr,tbl_df) |
|||
importFrom(pbapply,pblapply) |
|||
importFrom(utils,read.table) |
|||
|
@ -0,0 +1,11 @@ |
|||
#' A package to Count Lines of Code, Comments and Whitespace in Source Files and Archives |
|||
#' @name cloc-package |
|||
#' @docType package |
|||
#' @author Bob Rudis (@@hrbrmstr) |
|||
#' @importFrom R.utils isUrl |
|||
#' @importFrom utils read.table |
|||
#' @importFrom dplyr tbl_df |
|||
#' @importFrom dplyr bind_rows |
|||
#' @importFrom dplyr rbind_list |
|||
#' @importFrom pbapply pblapply |
|||
NULL |
@ -0,0 +1,78 @@ |
|||
#' Count lines of code, comments and whitespace in source files/archives |
|||
#' |
|||
#' @param source thing to extract from |
|||
#' @param extract_with thing |
|||
#' @return \code{tbl_df} |
|||
#' @export |
|||
cloc <- function(source, extract_with=NULL) { |
|||
|
|||
is_url <- isUrl(source) |
|||
|
|||
if (is_url) { |
|||
dir <- tempdir() |
|||
download.file(source, file.path(dir, basename(source)), method="curl") |
|||
source <- file.path(dir, basename(source)) |
|||
} |
|||
|
|||
stopifnot(file.exists(source)) |
|||
|
|||
cmd <- sprintf("perl %s --quiet --csv %s", |
|||
system.file("bin/cloc.pl", package="cloc"), |
|||
source) |
|||
|
|||
if (!is.null(extract_with)) cmd <- sprintf('%s --extract-with="%s"', cmd, extract_with) |
|||
|
|||
dat <- system(cmd, intern=TRUE) |
|||
|
|||
fil <- read.table(text=paste(tail(dat, -2), sep="", collapse="\n"), |
|||
col.names=c("file_count", "language", "blank_lines", |
|||
"comment_lines", "loc"), |
|||
sep=",", stringsAsFactors=FALSE) |
|||
|
|||
if (is_url) unlink(source) |
|||
|
|||
# calculate percentages |
|||
|
|||
fil$source <- basename(source) |
|||
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) |
|||
fil$loc_pct <- fil$loc / sum(fil$loc) |
|||
|
|||
tbl_df(fil[, c("source", "language", |
|||
"file_count", "file_count_pct", |
|||
"loc", "loc_pct", |
|||
"blank_lines", "blank_line_pct", |
|||
"comment_lines", "comment_line_pct")]) |
|||
|
|||
} |
|||
|
|||
#' Count lines of code (etc) from source packages on CRAN |
|||
#' |
|||
#' @param pkgs names of pkgs |
|||
#' @param repos repos |
|||
#' @param contriburl |
|||
#' @return \code{tbl_df} |
|||
#' @export |
|||
cloc_cran <- function(pkgs, |
|||
repos = getOption("repos"), |
|||
contriburl = contrib.url(repos, "source")) { |
|||
|
|||
destdir <- tempfile() |
|||
dir.create(destdir) |
|||
|
|||
res_p <- as.data.frame(download.packages(pkgs, destdir, repos=repos, |
|||
contriburl=contriburl, type="source"), |
|||
stringsAsFactors=FALSE) |
|||
|
|||
res <- bind_rows(pblapply(res_p$V2, function(x) { |
|||
ret <- cloc(x) |
|||
ret$pkg <- res_p[res_p$V2==x,]$V1 |
|||
ret |
|||
})) |
|||
|
|||
unlink(destdir, recursive=TRUE) |
|||
|
|||
res |
|||
|
|||
} |
@ -0,0 +1,66 @@ |
|||
--- |
|||
output: |
|||
md_document: |
|||
variant: markdown_github |
|||
--- |
|||
|
|||
<!-- README.md is generated from README.Rmd. Please edit that file --> |
|||
|
|||
```{r, echo = FALSE} |
|||
knitr::opts_chunk$set( |
|||
collapse = TRUE, |
|||
comment = "#>", |
|||
fig.path = "README-" |
|||
) |
|||
``` |
|||
|
|||
[](https://travis-ci.org/hrbrmstr/cloc) |
|||
](http://www.repostatus.org/#concept) |
|||
[](http://cran.r-project.org/web/packages/cloc) |
|||
 |
|||
|
|||
cloc is ... |
|||
|
|||
The following functions are implemented: |
|||
|
|||
The following data sets are included: |
|||
|
|||
### News |
|||
|
|||
- Version released |
|||
|
|||
### Installation |
|||
|
|||
```{r eval=FALSE} |
|||
devtools::install_github("hrbrmstr/cloc") |
|||
``` |
|||
|
|||
```{r echo=FALSE, message=FALSE, warning=FALSE, error=FALSE} |
|||
options(width=120) |
|||
``` |
|||
|
|||
### Usage |
|||
|
|||
```{r} |
|||
library(cloc) |
|||
|
|||
# current verison |
|||
packageVersion("cloc") |
|||
|
|||
``` |
|||
|
|||
### Test Results |
|||
|
|||
```{r} |
|||
library(cloc) |
|||
library(testthat) |
|||
|
|||
date() |
|||
|
|||
test_dir("tests/") |
|||
``` |
|||
|
|||
### 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. |
@ -0,0 +1,66 @@ |
|||
--- |
|||
output: |
|||
md_document: |
|||
variant: markdown_github |
|||
--- |
|||
|
|||
<!-- README.md is generated from README.Rmd. Please edit that file --> |
|||
|
|||
|
|||
|
|||
[](https://travis-ci.org/hrbrmstr/cloc) |
|||
](http://www.repostatus.org/#concept) |
|||
[](http://cran.r-project.org/web/packages/cloc) |
|||
 |
|||
|
|||
cloc is ... |
|||
|
|||
The following functions are implemented: |
|||
|
|||
The following data sets are included: |
|||
|
|||
### News |
|||
|
|||
- Version released |
|||
|
|||
### Installation |
|||
|
|||
|
|||
```r |
|||
devtools::install_github("hrbrmstr/cloc") |
|||
``` |
|||
|
|||
|
|||
|
|||
### Usage |
|||
|
|||
|
|||
```r |
|||
library(cloc) |
|||
#> Error in library(cloc): there is no package called 'cloc' |
|||
|
|||
# current verison |
|||
packageVersion("cloc") |
|||
#> Error in packageVersion("cloc"): package 'cloc' not found |
|||
``` |
|||
|
|||
### Test Results |
|||
|
|||
|
|||
```r |
|||
library(cloc) |
|||
#> Error in library(cloc): there is no package called 'cloc' |
|||
library(testthat) |
|||
#> Loading required package: methods |
|||
|
|||
date() |
|||
#> [1] "Tue Jun 30 22:51:36 2015" |
|||
|
|||
test_dir("tests/") |
|||
#> Error in library(cloc): there is no package called '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. |
Binary file not shown.
File diff suppressed because it is too large
@ -0,0 +1,13 @@ |
|||
% Generated by roxygen2 (4.1.1): do not edit by hand |
|||
% Please edit documentation in R/cloc-package.r |
|||
\docType{package} |
|||
\name{cloc-package} |
|||
\alias{cloc-package} |
|||
\title{A package to Count Lines of Code, Comments and Whitespace in Source Files and Archives} |
|||
\description{ |
|||
A package to Count Lines of Code, Comments and Whitespace in Source Files and Archives |
|||
} |
|||
\author{ |
|||
Bob Rudis (@hrbrmstr) |
|||
} |
|||
|
@ -0,0 +1,20 @@ |
|||
% Generated by roxygen2 (4.1.1): do not edit by hand |
|||
% Please edit documentation in R/cloc.R |
|||
\name{cloc} |
|||
\alias{cloc} |
|||
\title{Count lines of code, comments and whitespace in source files/archives} |
|||
\usage{ |
|||
cloc(source, extract_with = NULL) |
|||
} |
|||
\arguments{ |
|||
\item{source}{thing to extract from} |
|||
|
|||
\item{extract_with}{thing} |
|||
} |
|||
\value{ |
|||
\code{tbl_df} |
|||
} |
|||
\description{ |
|||
Count lines of code, comments and whitespace in source files/archives |
|||
} |
|||
|
@ -0,0 +1,23 @@ |
|||
% Generated by roxygen2 (4.1.1): do not edit by hand |
|||
% Please edit documentation in R/cloc.R |
|||
\name{cloc_cran} |
|||
\alias{cloc_cran} |
|||
\title{Count lines of code (etc) from source packages on CRAN} |
|||
\usage{ |
|||
cloc_cran(pkgs, repos = getOption("repos"), contriburl = contrib.url(repos, |
|||
"source")) |
|||
} |
|||
\arguments{ |
|||
\item{pkgs}{names of pkgs} |
|||
|
|||
\item{repos}{repos} |
|||
|
|||
\item{contriburl}{} |
|||
} |
|||
\value{ |
|||
\code{tbl_df} |
|||
} |
|||
\description{ |
|||
Count lines of code (etc) from source packages on CRAN |
|||
} |
|||
|
@ -0,0 +1,4 @@ |
|||
library(testthat) |
|||
library(cloc) |
|||
|
|||
test_check("cloc") |
@ -0,0 +1,6 @@ |
|||
context("basic functionality") |
|||
test_that("we can do something", { |
|||
|
|||
#expect_that(some_function(), is_a("data.frame")) |
|||
|
|||
}) |
Loading…
Reference in new issue