Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grooming up to regular Bioc package #1

Open
wants to merge 14 commits into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
TODO.org
^.*\.Rproj$
^\.Rproj\.user$
README.md
6 changes: 4 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
Package: codetoolsBioC
Title: Bioconductor Extensions for R Code Analysis Tools
Description: Bioconductor extensions for R code analysis tools.
Version: 0.1-0
Version: 0.99.0
Authors@R: c(
person("Patrick", "Aboyoun", role="aut"),
person("Martin", "Maechler", role="aut"),
person("Henrik", "Bengtsson", role="ctb"),
person("Bioconductor Package Maintainer", role="cre", email="[email protected]"))
Depends: R (>= 2.1)
Imports: codetools, methods, utils
Imports: codetools, methods, utils, stats
Suggests: stats4, Matrix, aroma.core
License: Artistic-2.0
Encoding: UTF-8
biocViews: Infrastructure
RoxygenNote: 7.1.0
25 changes: 17 additions & 8 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import(codetools)

importFrom("methods", findClass, findFunction, getClassDef, getClasses,
getFunction, isClass, listFromMlist, slot)
# Generated by roxygen2: do not edit by hand

importFrom("utils", find, packageDescription)

export(findExternalDeps, writeNamespaceImports, getRdFileNames,
writeRUnitRunner)
export(findExternalDeps)
export(getRdFileNames)
export(writeNamespaceImports)
export(writeRUnitRunner)
import(codetools)
importFrom(methods,findClass)
importFrom(methods,findFunction)
importFrom(methods,getClassDef)
importFrom(methods,getClasses)
importFrom(methods,getFunction)
importFrom(methods,isClass)
importFrom(methods,listFromMlist)
importFrom(methods,slot)
importFrom(stats,setNames)
importFrom(utils,find)
importFrom(utils,packageDescription)
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# codetoolsBioC 0.99.0

* Added a `NEWS.md` file to track changes to the package.
* Started the process to make this a fully fledged Bioc package
13 changes: 13 additions & 0 deletions R/codetoolsBioc-pkg.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#' codetoolsBioc
#'
#' `codetoolsBioc` is a Bioconductor package that provides ...
#'
#' @import codetools
#' @importFrom methods findClass findFunction getClassDef getClasses
#' getFunction isClass listFromMlist slot
#' @importFrom utils find packageDescription
#' @importFrom stats setNames
#'
#' @name codetoolsBioc-pkg
#' @docType package
NULL
23 changes: 23 additions & 0 deletions R/findExternalDeps.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,29 @@ loadRequiredPackages <- function(package)
}
}



#' Find External Dependencies of a Package
#'
#' Finds external dependencies of a package.
#'
#' The result is an approximation based upon the findings of \code{findGlobals}
#' and an exploration of the package namespace.
#'
#' @param package the quoted name of the package to analyze.
#' @return A list with four components: \code{S4Classes}, \code{S4Methods},
#' \code{functions}, and \code{variables}. Each of these components in turn
#' holds a named list of character vectors of object names from external
#' packages.
#' @author Patrick Aboyoun
#' @export
#' @seealso \code{\link[codetools]{findGlobals}},
#' %\code{\link[codetools]{checkUsagePackage}}, Rd file not found.
#' @keywords programming
#' @examples
#'
#' library(stats4)
#' findExternalDeps("stats4")
findExternalDeps <- function(package) {
loadRequiredPackages(package)
pkgEnv <- getPackageEnvironment(package)
Expand Down
2 changes: 1 addition & 1 deletion R/getNamespaceFileImports.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ getNamespaceFileImports <- function(package, lib.loc = .libPaths()) {
} else {
fgen <- fileContents[["general"]]
nms.fgen <- names(fgen)
X <- setNames(seq_along(fgen), nms.fgen)
X <- setNames(seq_along(fgen), nms.fgen)
funsAndVars <- lapply(X, function(i) {
x.i <- fgen[[i]]
isFunction <- vapply(x.i, function(y)
Expand Down
27 changes: 25 additions & 2 deletions R/getRdFileNames.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
#' Track Rd file names at which 'topic' is documented
#'
#' Tracks the Rd file names at which a given 'topic' (alias) is documented.
#'
#' @param topic A length-one character vector specifying the topic (alias).
#' @param package A character vector given the packages to search for Rd file
#' names that document the \code{topic} , or 'NULL'. By default, all the
#' packages in the search path are used.
#' @author Chao-Jen Wong \email{cwon2@@fhcrc.org}
#' @export
#' @keywords programming
#' @examples
#'
#' getRdFileNames("rbind")
#'
#' isInstalled <- function(pkg)
#' inherits(suppressWarnings(packageDescription(pkg)), "packageDescription")
#'
#' if (isInstalled("IRanges"))
#' getRdFileNames("rbind", package=c("base", "IRanges"))
#'
#' if (isInstalled("Biobase"))
#' getRdFileNames("ExpressionSet", "Biobase")
#'
getRdFileNames <- function(topic, package=NULL)
{
## Imports
Expand Down Expand Up @@ -26,5 +50,4 @@ getRdFileNames <- function(topic, package=NULL)
paths <- unlist(paths)

data.frame(packages=basename(names(paths)), Rd.file=basename(paths))
}

}
4 changes: 1 addition & 3 deletions R/utility-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ getPackageEnvironment <- function(package) {
## common idioms
ulapply <- function(...) unlist(lapply(...))

suniquec <-
function(X, Y, what)
suniquec <- function(X, Y, what) {
## optionally subset Y by elements named 'what', then make unique
## set with X
{
if (!missing(what))
Y <- ulapply(Y, "[[", what)
sort(unique(c(X, Y)))
Expand Down
49 changes: 41 additions & 8 deletions R/writeNamespaceImports.R
Original file line number Diff line number Diff line change
@@ -1,12 +1,45 @@
writeNamespaceImports <-
function(package, file = "", append = TRUE, quote = FALSE,
width = 0.9 * getOption("width"))
{
#' Write NAMESPACE file imports statements
#'
#' Writes imports statements that can be included in a package's NAMESPACE
#' file.
#'
#' The result is an approximation based upon the findings of
#' \code{\link{findExternalDeps}}. S4 class dependencies are embedded into
#' importClassesFrom statements, S4 methods dependencies are embedded into
#' importMethodsFrom statements, and all other dependencies are embedded into
#' importFrom statements.
#'
#' See the document "Writing R Extensions" that is hosted on CRAN for more
#' details on the proper construction of a NAMESPACE file.
#'
#' @param package the quoted name of the package to analyze.
#' @param file either a character string naming a file or an open writing
#' connection. \code{""} indicates writing to the console.
#' @param append logical. If \code{TRUE}, the output is appended to the file.
#' If \code{FALSE}, any existing file with the specified name is destroyed and
#' a new one is created. This argument is only used if \code{file} is a
#' character string.
#' @param quote logical. If \code{TRUE}, all import fields will be
#' double-quoted. If \code{FALSE}, only non-standard names like
#' \code{[<-.fractions} will be double-quoted.
#' @param width a positive integer giving the target column for wrapping lines
#' in the output.
#' @author Patrick Aboyoun
#' @export
#' @seealso \code{\link{findExternalDeps}}
#' @keywords programming
#' @examples
#'
#' library(stats4)
#' writeNamespaceImports("stats4")
#'
writeNamespaceImports <- function(package, file = "", append = TRUE, quote = FALSE,
width = 0.9 * getOption("width")) {
writeImports <- function(x, prefix, file, width) {
Rkeywords <-
c("NULL", "NA", "TRUE", "FALSE", "Inf", "NaN", "NA_integer_",
"NA_real_", "NA_character_", "NA_complex_", "function", "while",
"repeat", "for", "if", "in", "else", "next", "break", "...")
c("NULL", "NA", "TRUE", "FALSE", "Inf", "NaN", "NA_integer_",
"NA_real_", "NA_character_", "NA_complex_", "function", "while",
"repeat", "for", "if", "in", "else", "next", "break", "...")
for (i in which(!(names(x) %in% ignoredPackages))) {
if (quote) {
qstring1 <- "\""
Expand Down Expand Up @@ -37,7 +70,7 @@ writeNamespaceImports <-
}
if (!inherits(file, "connection"))
stop("'file' must be a character string or connection")

allDeps <- findExternalDeps(package)
allDepNames <- sort(unique(ulapply(allDeps, names)))
allDepNames <- allDepNames[!(allDepNames %in% ignoredPackages)]
Expand Down
30 changes: 30 additions & 0 deletions R/writeRUnitRunner.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
#' Write an R code file containing a .test function to run RUnit tests
#'
#' This function generates an R code file containing a single function
#' \code{.test} that can be used to run the RUnit unit tests of a package. The
#' generated \code{.test} function is customized for the specified package and
#' takes care of setting up RUnit options, configuring the location of unit
#' test files, and generating helpful summary data when tests fail.
#'
#'
#' Copy the generated file, or its contents, into your package source. You can
#' add an additional R script in pkg/tests that loads your package and then
#' calls \code{pkg:::.test()}. This will ensure that unit tests are run during
#' R CMD check and that a unit test failure will result in an ERROR report from
#' R CMD check.
#'
#' @param pkg Package name: a \code{.test} function will be generated
#' customized for the specified package name.
#' @param file Determines the file where code for the \code{.test} function
#' will be written.
#' @return Called for the side-effect of creating a file containing the
#' \code{.test} function definition customized for \code{pkg}.
#' @author Seth Falcon
#' @export
#' @examples
#'
#' tf <- tempfile()
#' writeRUnitRunner("foo", tf)
#' lines <- readLines(tf)
#' file.remove(tf)
#'
writeRUnitRunner <- function(pkg, file = "runit_runner.R")
{
line <- paste0("BiocGenerics:::testPackage(\"", pkg, "\")")
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# codetoolsBioC

The goal of `codetoolsBioc` is...

## Installation

```
remotes::install_github("Bioconductor/codetoolsBioc")
remotes::install_github("federicomarini/codetoolsBioc") # for the current fork...
```
9 changes: 9 additions & 0 deletions man/codetoolsBioc-pkg.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 19 additions & 14 deletions man/findExternalDeps.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 16 additions & 14 deletions man/getRdFileNames.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading