Title: Package development helper
Author: Benjamin Auder
Maintainer: Benjamin Auder <Benjamin.Auder@gmail.com>
-Depends: R (>= 2.15.1)
+Depends:
+ R (>= 2.15.1)
Description: Allow nested subfolders in R/ directory,
- and somewhat simplify testing process
+ and somewhat simplify testing process
License: GPL (>= 3)
LazyLoad: yes
if (fileOrDir != forbiddenPath) {
if (file.info(fileOrDir)$isdir) {
rFiles = list.files(fileOrDir, pattern="\\.[RrSsq]$",
- full.names=TRUE, recursive=TRUE)
+ full.names=TRUE, recursive=TRUE)
# NOTE: potential unexported functions are not hidden;
# the developer is assumed to handle this
lapply(rFiles, source)
# This file tells if the package is currently loaded
pkgLoadFile = file.path(pkdev_path,"pkgs",pkgName,"loaded")
-
+
if (file.exists(file.path(path,"src"))) {
# C code -- Warning: src/tests folder should not be listed
- cFiles = c(
- list.files( file.path(path,"src","adapters"), pattern="\\.[cChH]$",
- full.names=TRUE, recursive=TRUE ),
- list.files( file.path(path,"src","sources"), pattern="\\.[cChH]$",
- full.names=TRUE, recursive=TRUE ))
+ cFiles = list.files( file.path(path,"src"), pattern="\\.[cChH]$",
+ full.names=TRUE, recursive=TRUE, no..=TRUE )
+ cFiles = lapply(cFiles, function(x) {
+ if (nchar(x)>=5 && substr(x,1,5)=="tests") return ("")
+ return (x)
+ })
# Create folder R_HOME_USER/pkgdev/pkgs/pkgName/src (if not existing)
dir.create(file.path(pkdev_path,"pkgs",pkgName,"src"), showWarnings=FALSE)
}
# Mark package as 'loaded'
- writeLines("loaded",pkgLoadFile)
+ file.create(pkgLoadFile)
}
# Generate appropriate Makefile under R_HOME_USER/pkgdev/pkgs/pkgName/src
-# Setup a file structure under R_HOME/pkgdev/ to run later tests
+# Setup a file structure under R_HOME_USER/pkgdev/ to run later tests
# @param atInstall Logical, TRUE if invoked at package installation
.pkgdev.setup = function(reset=FALSE) {
cat("*** WARNING: for pkgdev to work properly, you need to specify\n")
cat("*** an environment variable R_HOME_USER in a .Renviron file.\n")
cat("*** Standard choice is /home/userName/.R under UNIX systems,\n")
- cat("*** or maybe C:/Users/userName/Documents/R under Windows")
+ cat("*** or maybe C:/Users/userName/Documents/R under Windows\n")
stop("Please specify R_HOME_USER before using pkgdev")
}
-TODO
+|--------------
+| Basic usage :
+|--------------
+
+#Install
+R CMD INSTALL path/to/pkgdev/folder
+
+#Launch R
+R
+
+#load library
+library(pkgdev)
+
+#load some package
+pkgpath = "path/to/some/package"
+pkgdev.load(pkgpath)
+
+#test it (if unit tests defined under tests/ subfolders)
+pkgdev.rtest(pkgpath)
+pkgdev.rtest(pkgpath)
+
+#you can also run its functions
+foo(...)
+bar(...)
+
+#reload package to test modifications
+pkgdev.load(pkgpath)
+
+#...and so on
+
+#finally, unload package
+pkgdev.unload(pkgpath)
+
+---------------------------------
+
+Try also pkgTest/ testing package
--- /dev/null
+% Generated by roxygen2 (4.0.2): do not edit by hand
+\name{pkgdev.check}
+\alias{pkgdev.check}
+\title{Invoke R CMD check on a flat package (maybe with optional arguments, like --as-cran)}
+\usage{
+pkgdev.check(path, opts)
+}
+\arguments{
+\item{opts}{Vector of strings arguments to pass to R CMD CHECK}
+}
+\description{
+Invoke R CMD check on a flat package (maybe with optional arguments, like --as-cran)
+}
+
--- /dev/null
+% Generated by roxygen2 (4.0.2): do not edit by hand
+\name{pkgdev.clean}
+\alias{pkgdev.clean}
+\title{Wipe a specific package under R_HOME_USER/pkgdev/pkgs/
+NOTE: when this package will be loaded again, it will be completely rebuilt}
+\usage{
+pkgdev.clean(pkgName)
+}
+\arguments{
+\item{pkgName}{Name of the package to be removed}
+}
+\description{
+Wipe a specific package under R_HOME_USER/pkgdev/pkgs/
+NOTE: when this package will be loaded again, it will be completely rebuilt
+}
+
--- /dev/null
+% Generated by roxygen2 (4.0.2): do not edit by hand
+\name{pkgdev.ctest}
+\alias{pkgdev.ctest}
+\title{Launch C unit tests (arbitrary file structure under src/tests), or display the list of test functions}
+\usage{
+pkgdev.ctest(path, prefix = "", show = FALSE, cc = "gcc -std=gnu99")
+}
+\arguments{
+\item{path}{Location of the package containing tests (under /src/tests)}
+
+\item{prefix}{Prefix for names of the functions to be tested; leave empty to test all (default)}
+
+\item{show}{Logical, TRUE to display the list of unit tests (default: FALSE)}
+}
+\description{
+Launch C unit tests (arbitrary file structure under src/tests), or display the list of test functions
+}
+
--- /dev/null
+% Generated by roxygen2 (4.0.2): do not edit by hand
+\name{pkgdev.load}
+\alias{pkgdev.load}
+\title{Load a package containing arbitrary file structures under R/ and src/{adapters,sources}}
+\usage{
+pkgdev.load(path, cc = "gcc -std=gnu99")
+}
+\arguments{
+\item{path}{Location of the package to load}
+
+\item{cc}{Compilator to be used (e.g. 'gcc -std=gnu99' [default])}
+}
+\description{
+Load a package containing arbitrary file structures under R/ and src/{adapters,sources}
+}
+
--- /dev/null
+% Generated by roxygen2 (4.0.2): do not edit by hand
+\name{pkgdev.rtest}
+\alias{pkgdev.rtest}
+\title{Launch R unit tests (arbitrary file structure under R/tests), or display the list of test functions}
+\usage{
+pkgdev.rtest(path, prefix = "", show = FALSE, cc = "gcc -std=gnu99")
+}
+\arguments{
+\item{path}{Location of the package containing tests (under /R/tests)}
+
+\item{prefix}{Prefix for names of the functions to be tested; leave empty to test all (default)}
+
+\item{show}{Logical, TRUE to display the list of unit tests (default: FALSE)}
+}
+\description{
+Launch R unit tests (arbitrary file structure under R/tests), or display the list of test functions
+}
+
--- /dev/null
+% Generated by roxygen2 (4.0.2): do not edit by hand
+\name{pkgdev.tocran}
+\alias{pkgdev.tocran}
+\title{"Flatten" a package: gather all sources under R/ and src/ without hierarchical file structure}
+\usage{
+pkgdev.tocran(inPath, outPath = NULL)
+}
+\arguments{
+\item{inPath}{Input path: location of the package to flatten}
+
+\item{outPath}{Output path: location of the package to create [default: inPath_cran]}
+}
+\description{
+"Flatten" a package: gather all sources under R/ and src/ without hierarchical file structure
+}
+
--- /dev/null
+% Generated by roxygen2 (4.0.2): do not edit by hand
+\name{pkgdev.unload}
+\alias{pkgdev.unload}
+\title{Unload a package containing arbitrary file structures under R/ and src/{adapters,sources}}
+\usage{
+pkgdev.unload(path)
+}
+\arguments{
+\item{path}{Location or name of the package to unload}
+}
+\description{
+Unload a package containing arbitrary file structures under R/ and src/{adapters,sources}
+}
+
--- /dev/null
+% Generated by roxygen2 (4.0.2): do not edit by hand
+\name{pkgdev.wipeAll}
+\alias{pkgdev.wipeAll}
+\title{Reset pkgdev folder under R_HOME_USER
+WARNING: all loaded packages will have to be rebuilt}
+\usage{
+pkgdev.wipeAll()
+}
+\description{
+Reset pkgdev folder under R_HOME_USER
+WARNING: all loaded packages will have to be rebuilt
+}
+
--- /dev/null
+Package: pkgTest
+Type: Package
+Version: 0.1.0
+Date: 2015-01-31
+Title: Just a Testing Package
+Author: Benjamin Auder
+Maintainer: Benjamin Auder <Benjamin.Auder@math.u-psud.fr>
+Depends: R (>= 2.14.1)
+Description: testing package for pkgdev
+License: GPL (>= 3)
+LazyLoad: yes
--- /dev/null
+# Export all user-level R functions
+export (a, b, c, .Last.lib)
+
+useDynLib(pkgTest)
--- /dev/null
+a = function() {
+ print("Hello World, I'm a()")
+}
--- /dev/null
+b = function() {
+ print("Hello, I'm b()")
+ r = 0
+ result = .C("d", result = as.integer(r), package="pkg_test")$result
+ print(paste("The result is ", result))
+}
--- /dev/null
+c = function() {
+ print("And this is c()")
+}
--- /dev/null
+#called when package is detached ( detach("package:pkg_name") )
+.Last.lib = function(path)
+{
+ library.dynam.unload("pkgTest", path)
+}
--- /dev/null
+void d(int* result) {
+ *result = 32;
+}