| 1 | # Main wrapped entry point: call package function 'func' |
| 2 | .execMethod = function(func, ...) { |
| 3 | |
| 4 | # check for R_HOME_USER variable, and for R_HOME_USER/pkgdev folder |
| 5 | .pkgdev.setup() |
| 6 | |
| 7 | # get appropriate core function and call it |
| 8 | func = match.fun(func) |
| 9 | func(...) |
| 10 | } |
| 11 | |
| 12 | #' Reset pkgdev folder under R_HOME_USER |
| 13 | #' WARNING: all loaded packages will have to be rebuilt |
| 14 | pkgdev.wipeAll = function() { |
| 15 | .pkgdev.setup(reset=TRUE) |
| 16 | } |
| 17 | |
| 18 | #' Load a package containing arbitrary file structures under R/ and src/{adapters,sources} |
| 19 | #' |
| 20 | #' @param path Location of the package to load |
| 21 | #' @param cc Compilator to be used (e.g. 'gcc -std=gnu99' [default]) |
| 22 | pkgdev.load = function(path, cc="gcc -std=gnu99") { |
| 23 | path = normalizePath(path) #allow to give only pkg name (in pkg/.. folder) |
| 24 | .execMethod(".pkgdev.load", path, cc) |
| 25 | } |
| 26 | |
| 27 | #' Unload a package containing arbitrary file structures under R/ and src/{adapters,sources} |
| 28 | #' |
| 29 | #' @param path Location or name of the package to unload |
| 30 | pkgdev.unload = function(path) { |
| 31 | path = normalizePath(path) #allow to give only pkg name (in pkg/.. folder) |
| 32 | .execMethod(".pkgdev.unload", path) |
| 33 | } |
| 34 | |
| 35 | #' Wipe a specific package under R_HOME_USER/pkgdev/pkgs/ |
| 36 | #' NOTE: when this package will be loaded again, it will be completely rebuilt |
| 37 | #' |
| 38 | #' @param pkgName Name of the package to be removed |
| 39 | pkgdev.clean = function(pkgName) { |
| 40 | unlink(file.path(Sys.getenv("R_HOME_USER"),"pkgdev","pkgs",pkgName), recursive=TRUE) |
| 41 | unlink(file.path(Sys.getenv("R_HOME_USER"),"pkgdev","pkgs",pkgName), recursive=TRUE) #bug? |
| 42 | } |
| 43 | |
| 44 | #' Launch R unit tests (arbitrary file structure under R/tests), or display the list of test functions |
| 45 | #' |
| 46 | #' @param path Location of the package containing tests (under /R/tests) |
| 47 | #' @param prefix Prefix for names of the functions to be tested; leave empty to test all (default) |
| 48 | #' @param show Logical, TRUE to display the list of unit tests (default: FALSE) |
| 49 | pkgdev.rtest = function(path, prefix="", show=FALSE, cc="gcc -std=gnu99") { |
| 50 | path = normalizePath(path) #allow to give only pkg name (in pkg/.. folder) |
| 51 | .execMethod(".pkgdev.rtest", path, prefix, show, cc) |
| 52 | } |
| 53 | |
| 54 | #' Launch C unit tests (arbitrary file structure under src/tests), or display the list of test functions |
| 55 | #' |
| 56 | #' @param path Location of the package containing tests (under /src/tests) |
| 57 | #' @param prefix Prefix for names of the functions to be tested; leave empty to test all (default) |
| 58 | #' @param show Logical, TRUE to display the list of unit tests (default: FALSE) |
| 59 | pkgdev.ctest = function(path, prefix="", show=FALSE, cc="gcc -std=gnu99") { |
| 60 | .execMethod(".pkgdev.ctest", path, prefix, show, cc) |
| 61 | } |
| 62 | |
| 63 | #' "Flatten" a package: gather all sources under R/ and src/ without hierarchical file structure |
| 64 | #' |
| 65 | #' @param inPath Input path: location of the package to flatten |
| 66 | #' @param outPath Output path: location of the package to create [default: inPath_cran] |
| 67 | pkgdev.tocran = function(inPath, outPath=NULL) { |
| 68 | inPath = normalizePath(inPath) #allow to give only pkg name (in pkg/.. folder) |
| 69 | if (is.null(outPath)) outPath = paste(inPath, "_cran", sep='') |
| 70 | .execMethod(".pkgdev.tocran", inPath, outPath) |
| 71 | } |
| 72 | |
| 73 | #' Invoke R CMD check on a flat package (maybe with optional arguments, like --as-cran) |
| 74 | #' |
| 75 | #' @param opts Vector of strings arguments to pass to R CMD CHECK |
| 76 | pkgdev.check = function(path, opts) { |
| 77 | path = normalizePath(path) #allow to give only pkg name (in pkg/.. folder) |
| 78 | system( paste("R CMD check", opts, path, sep=' ') ) |
| 79 | } |