Browse Source

intial commit

pull/1/head
Bob Rudis 9 years ago
parent
commit
0afce2078e
  1. 5
      .Rbuildignore
  2. 14
      .travis.yml
  3. 25
      CONDUCT.md
  4. 8
      DESCRIPTION
  5. 11
      NAMESPACE
  6. 11
      R/cloc-package.r
  7. 78
      R/cloc.R
  8. 66
      README.Rmd
  9. 66
      README.md
  10. 9
      cloc.Rproj
  11. BIN
      inst/bin/cloc.exe
  12. 10483
      inst/bin/cloc.pl
  13. 0
      inst/bin/eg1.tex
  14. 13
      man/cloc-package.Rd
  15. 20
      man/cloc.Rd
  16. 23
      man/cloc_cran.Rd
  17. 4
      tests/testthat.R
  18. 6
      tests/testthat/test-cloc.R

5
.Rbuildignore

@ -1,2 +1,7 @@
^.*\.Rproj$ ^.*\.Rproj$
^\.Rproj\.user$ ^\.Rproj\.user$
^README\.Rmd$
^README-.*\.png$
^\.travis\.yml$
^CONDUCT\.md$
^README\.md$

14
.travis.yml

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

25
CONDUCT.md

@ -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/

8
DESCRIPTION

@ -1,8 +1,10 @@
Package: cloc 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 Version: 0.0.0.9000
Authors@R: c(person("Bob", "Rudis", email = "bob@rudis.net", role = c("aut", "cre"))) Authors@R: c(person("Bob", "Rudis", email = "bob@rudis.net", role = c("aut", "cre")))
Description: What the package does (one paragraph). Description: Count lines of code!
Depends: R (>= 3.2.1) Imports: R.utils, utils, dplyr, pbapply
Depends: R (>= 3.2.0)
License: MIT + file LICENSE License: MIT + file LICENSE
LazyData: true LazyData: true
Suggests: testthat

11
NAMESPACE

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

11
R/cloc-package.r

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

78
R/cloc.R

@ -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
}

66
README.Rmd

@ -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-"
)
```
[![Build Status](https://travis-ci.org/hrbrmstr/cloc.svg)](https://travis-ci.org/hrbrmstr/cloc)
![Project Status: Concept - Minimal or no implementation has been done yet.](http://www.repostatus.org/badges/0.1.0/concept.svg)](http://www.repostatus.org/#concept)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/cloc)](http://cran.r-project.org/web/packages/cloc)
![downloads](http://cranlogs.r-pkg.org/badges/grand-total/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.

66
README.md

@ -0,0 +1,66 @@
---
output:
md_document:
variant: markdown_github
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
[![Build Status](https://travis-ci.org/hrbrmstr/cloc.svg)](https://travis-ci.org/hrbrmstr/cloc)
![Project Status: Concept - Minimal or no implementation has been done yet.](http://www.repostatus.org/badges/0.1.0/concept.svg)](http://www.repostatus.org/#concept)
[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/cloc)](http://cran.r-project.org/web/packages/cloc)
![downloads](http://cranlogs.r-pkg.org/badges/grand-total/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.

9
cloc.Rproj

@ -14,3 +14,12 @@ BuildType: Package
PackageUseDevtools: Yes PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace PackageRoxygenize: rd,collate,namespace
UseSpacesForTab: Yes
NumSpacesForTab: 2
RnwWeave: Sweave
LaTeX: pdfLaTeX
PackageBuildArgs: --resave-data
PackageCheckArgs: --as-cran

BIN
inst/bin/cloc.exe

Binary file not shown.

10483
inst/bin/cloc.pl

File diff suppressed because it is too large

0
inst/bin/eg1.tex

13
man/cloc-package.Rd

@ -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)
}

20
man/cloc.Rd

@ -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
}

23
man/cloc_cran.Rd

@ -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
}

4
tests/testthat.R

@ -0,0 +1,4 @@
library(testthat)
library(cloc)
test_check("cloc")

6
tests/testthat/test-cloc.R

@ -0,0 +1,6 @@
context("basic functionality")
test_that("we can do something", {
#expect_that(some_function(), is_a("data.frame"))
})
Loading…
Cancel
Save