Skip to content

Commit

Permalink
bringing over some tools from optmatch: roxygen, more Makefile, spell…
Browse files Browse the repository at this point in the history
… checking
  • Loading branch information
markmfredrickson committed Nov 18, 2012
1 parent 4ab5d05 commit 841ee22
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .gitignore
@@ -1,4 +1,4 @@
*.RCheck
*.tar.gz
.local
RITOOLS_TIMESTAMP
RItools_*
6 changes: 3 additions & 3 deletions DESCRIPTION → DESCRIPTION.template
@@ -1,13 +1,13 @@
Package: RItools
Version:0.1-12
Date: 2010-03-07
Version: VERSION
Date: DATE
Title: Randomization inference tools
Author: Jake Bowers <jwbowers@illinois.edu>, Mark Fredrickson <mark.m.fredrickson@gmail.com>, and Ben Hansen <ben.hansen@umich.edu>
Maintainer: Jake Bowers <jwbowers@illinois.edu>
Description: Tools for randomization inference.
License: GPL (>=2)
Depends: R (>= 2.2.0), methods
Imports: graphics, stats, lattice, grid, SparseM, xtable
Suggests: optmatch, xtable
Suggests: optmatch, xtable, testthat
Enhances: optmatch, xtable
URL: http://CRAN.R-project.org/package=RItools, http://www.jakebowers.org/RItools.html
77 changes: 60 additions & 17 deletions Makefile
@@ -1,25 +1,68 @@
R: RITOOLS_TIMESTAMP
R_PROFILE=Rprofile R -q --no-save
R = R_LIBS=./local R

.local:
mkdir .local
R: .local/RItools/INSTALLED
$(R) -q --no-save

RITOOLS_TIMESTAMP: .local R/* tests/*
R --vanilla CMD Install --library=.local .
date > RITOOLS_TIMESTAMP
### Package release scripts ###

autotest: RITOOLS_TIMESTAMP
R -q -e "library(RItools, lib.loc = '.local')" \
-e "library(SparseM)" \
-e "library(testthat)" \
-e "auto_test_package('.')"
VERSION=0.1-12
RELEASE_DATE=`date +%Y-%m-%d`
PKG=RItools_$(VERSION)

build:
R --vanilla CMD Build .
# we depend on the makefile so that updates to the version number will force a rebuild
$(PKG): Makefile R/* tests/* inst/tests/* man/*
rm -rf $(PKG)
rsync -a --exclude-from=.gitignore --exclude=.git* --exclude Makefile \
--exclude=DESCRIPTION.template --exclude=NAMESPACE.static \
--exclude=lexicon.txt --exclude=README.md --exclude=checkspelling.R \
--exclude=RItools.Rcheck \
. $(PKG)

check: build
R --vanilla CMD Check RItools_0.1-12.tar.gz
$(PKG)/DESCRIPTION: $(PKG) DESCRIPTION.template
sed s/VERSION/$(VERSION)/ DESCRIPTION.template | sed s/DATE/$(RELEASE_DATE)/ > $(PKG)/DESCRIPTION

$(PKG)/NAMESPACE: $(PKG) $(PKG)/DESCRIPTION NAMESPACE.static
mkdir -p $(PKG)/man
$(R) -e "library(roxygen2); roxygenize('$(PKG)')"
cat NAMESPACE.static >> $(PKG)/NAMESPACE

$(PKG).tar.gz: $(PKG) $(PKG)/DESCRIPTION $(PKG)/NAMESPACE NEWS R/* data/* inst/* man/* tests/*
R --vanilla CMD build $(PKG)

package: $(PKG).tar.gz

# the spell task doesn't need the tar.gz particularly, but it does need DESCRIPTION and roxygen
spell: package
$(R) -q --no-save -e "source('checkspelling.R') ; check_spelling('$(PKG)')"

lexicon.txt: package
$(R) -q --no-save -e "source('checkspelling.R') ; make_dictionary('$(PKG)')"

# we don't use $(R) here in case the locally installed libs interfere with the check process
check: $(PKG).tar.gz
R --vanilla CMD check --as-cran --no-multiarch $(PKG).tar.gz

release: check spell
git tag -a $(VERSION)
@echo "Upload $(PKG).tar.gz to cran.r-project.org/incoming"
@echo "Email to CRAN@R-project.org, subject: 'CRAN submission RItools $(VERSION)'"

# depend on this file to decide if we need to install the local version
.local/RItools/INSTALLED: $(PKG).tar.gz
mkdir -p .local
R --vanilla CMD INSTALL --no-multiarch --library=.local $(PKG).tar.gz
echo `date` > .local/RItools/INSTALLED

# If we run into problems documenting S4 code, this helped
# .local/roxygen2/INSTALLED:
# mkdir -p .local
# R_LIBS=.local R --vanilla -e "library(devtools) ; install_github(repo = 'roxygen', user = 'klutometis', branch = 's4',args=c('--no-multiarch'))"
# echo `date` > .local/roxygen2/INSTALLED

# test is just the internal tests, not the full R CMD Check
test: .local/RItools/INSTALLED
R --vanilla -q -e "library(RItools, lib.loc = '.local'); library(testthat); test_package('RItools')"

clean:
git clean
git clean -xfd

File renamed without changes.
40 changes: 40 additions & 0 deletions checkspelling.R
@@ -0,0 +1,40 @@
check_spelling <- function(path) {
# this is usually loaded anyway, but just in case...
library("utils")

words <- aspell_package_Rd_files(path, program = "aspell", control = list("-p ./lexicon.txt"))

if (dim(words)[1] > 0) {
printAspellByFile(words)
stop("Correct spelling mistakes before proceeding.")
}

message("No spelling errors detected in documentation.")
}

printAspellByFile <- function (x, sort = TRUE, verbose = FALSE, indent = 2L, ...)
{
if (!(nr <- nrow(x)))
return(invisible(x))
if (sort)
x <- x[order(x$File, x$Original, x$Line, x$Column), ]
if (verbose)
out <- sprintf("%sWord: %s (%s:%d:%d)\n%s", c("", rep.int("\n",
nr - 1L)), x$Original, x$File, x$Line, x$Column,
formatDL(rep.int("Suggestions", nr), sapply(x$Suggestions,
paste, collapse = " "), style = "list"))
else {
s <- split(sprintf("%s:%d:%d", x$Original, x$Line, x$Column),
x$File)
sep <- sprintf("\n%s", paste(rep.int(" ", indent), collapse = ""))
out <- paste(names(s), sapply(s, paste, collapse = sep),
sep = sep, collapse = "\n\n")
}
writeLines(out)
invisible(x)
}

make_dictionary <- function(path) {
words <- aspell_package_Rd_files(path, program = "aspell")
aspell_write_personal_dictionary_file(words, out = "lexicon.txt", program = "aspell")
}

0 comments on commit 841ee22

Please sign in to comment.