From: Benjamin Auder Date: Sat, 31 Jan 2015 22:42:26 +0000 (+0100) Subject: first commit X-Git-Url: https://git.auder.net/variants/Chakart/pieces/current/doc/html/%7B%7B?a=commitdiff_plain;h=672594cf38591923d9735f532b29af0b6a69e5c9;p=pkgdev.git first commit --- diff --git a/DESCRIPTION b/DESCRIPTION old mode 100755 new mode 100644 index df83ff4..c324e30 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -5,8 +5,9 @@ Date: 2013-XX-XX Title: Package development helper Author: Benjamin Auder Maintainer: Benjamin Auder -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 diff --git a/R/load.R b/R/load.R index 4f74839..2d6d122 100644 --- a/R/load.R +++ b/R/load.R @@ -18,7 +18,7 @@ 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) @@ -33,14 +33,15 @@ # 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) @@ -64,7 +65,7 @@ } # Mark package as 'loaded' - writeLines("loaded",pkgLoadFile) + file.create(pkgLoadFile) } # Generate appropriate Makefile under R_HOME_USER/pkgdev/pkgs/pkgName/src diff --git a/R/setup.R b/R/setup.R index e95f9ca..30cecdf 100644 --- a/R/setup.R +++ b/R/setup.R @@ -1,4 +1,4 @@ -# 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) { @@ -7,7 +7,7 @@ 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") } diff --git a/README b/README index 1333ed7..be4a6d0 100644 --- a/README +++ b/README @@ -1 +1,36 @@ -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 diff --git a/man/pkgdev.check.Rd b/man/pkgdev.check.Rd new file mode 100644 index 0000000..de0a451 --- /dev/null +++ b/man/pkgdev.check.Rd @@ -0,0 +1,14 @@ +% 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) +} + diff --git a/man/pkgdev.clean.Rd b/man/pkgdev.clean.Rd new file mode 100644 index 0000000..339d9e6 --- /dev/null +++ b/man/pkgdev.clean.Rd @@ -0,0 +1,16 @@ +% 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 +} + diff --git a/man/pkgdev.ctest.Rd b/man/pkgdev.ctest.Rd new file mode 100644 index 0000000..821bfdb --- /dev/null +++ b/man/pkgdev.ctest.Rd @@ -0,0 +1,18 @@ +% 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 +} + diff --git a/man/pkgdev.load.Rd b/man/pkgdev.load.Rd new file mode 100644 index 0000000..6e00b05 --- /dev/null +++ b/man/pkgdev.load.Rd @@ -0,0 +1,16 @@ +% 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} +} + diff --git a/man/pkgdev.rtest.Rd b/man/pkgdev.rtest.Rd new file mode 100644 index 0000000..3f33f1f --- /dev/null +++ b/man/pkgdev.rtest.Rd @@ -0,0 +1,18 @@ +% 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 +} + diff --git a/man/pkgdev.tocran.Rd b/man/pkgdev.tocran.Rd new file mode 100644 index 0000000..fdc03f0 --- /dev/null +++ b/man/pkgdev.tocran.Rd @@ -0,0 +1,16 @@ +% 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 +} + diff --git a/man/pkgdev.unload.Rd b/man/pkgdev.unload.Rd new file mode 100644 index 0000000..337dc55 --- /dev/null +++ b/man/pkgdev.unload.Rd @@ -0,0 +1,14 @@ +% 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} +} + diff --git a/man/pkgdev.wipeAll.Rd b/man/pkgdev.wipeAll.Rd new file mode 100644 index 0000000..8dbe733 --- /dev/null +++ b/man/pkgdev.wipeAll.Rd @@ -0,0 +1,13 @@ +% 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 +} + diff --git a/pkgTest/DESCRIPTION b/pkgTest/DESCRIPTION new file mode 100644 index 0000000..ad059b8 --- /dev/null +++ b/pkgTest/DESCRIPTION @@ -0,0 +1,11 @@ +Package: pkgTest +Type: Package +Version: 0.1.0 +Date: 2015-01-31 +Title: Just a Testing Package +Author: Benjamin Auder +Maintainer: Benjamin Auder +Depends: R (>= 2.14.1) +Description: testing package for pkgdev +License: GPL (>= 3) +LazyLoad: yes diff --git a/pkgTest/NAMESPACE b/pkgTest/NAMESPACE new file mode 100755 index 0000000..c969d76 --- /dev/null +++ b/pkgTest/NAMESPACE @@ -0,0 +1,4 @@ +# Export all user-level R functions +export (a, b, c, .Last.lib) + +useDynLib(pkgTest) diff --git a/pkgTest/R/a.R b/pkgTest/R/a.R new file mode 100644 index 0000000..05dbee9 --- /dev/null +++ b/pkgTest/R/a.R @@ -0,0 +1,3 @@ +a = function() { + print("Hello World, I'm a()") +} diff --git a/pkgTest/R/folder/b.R b/pkgTest/R/folder/b.R new file mode 100644 index 0000000..3a3854b --- /dev/null +++ b/pkgTest/R/folder/b.R @@ -0,0 +1,6 @@ +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)) +} diff --git a/pkgTest/R/folder/subfolder/c.R b/pkgTest/R/folder/subfolder/c.R new file mode 100644 index 0000000..8a5bae3 --- /dev/null +++ b/pkgTest/R/folder/subfolder/c.R @@ -0,0 +1,3 @@ +c = function() { + print("And this is c()") +} diff --git a/pkgTest/R/zzz.R b/pkgTest/R/zzz.R new file mode 100644 index 0000000..415c03a --- /dev/null +++ b/pkgTest/R/zzz.R @@ -0,0 +1,5 @@ +#called when package is detached ( detach("package:pkg_name") ) +.Last.lib = function(path) +{ + library.dynam.unload("pkgTest", path) +} diff --git a/pkgTest/src/d.c b/pkgTest/src/d.c new file mode 100644 index 0000000..686dc56 --- /dev/null +++ b/pkgTest/src/d.c @@ -0,0 +1,3 @@ +void d(int* result) { + *result = 32; +}