From 5aeca7a0102aac06331337ef688e5c5ea7677568 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sat, 22 Oct 2016 17:41:50 +0200 Subject: [PATCH 01/26] oops --- NEWS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/NEWS.md b/NEWS.md index f1759ae..11e092f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,7 @@ - Travis tests three R versions, and OS X. + ## rprojroot 1.0-5 (2016-10-22) - Use Travis instead of wercker. From f50eb66dcaf08a5892515e590f5424981387163b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sat, 22 Oct 2016 17:48:02 +0200 Subject: [PATCH 02/26] structure --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 60b1c51..d0ac2f7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -58,3 +58,4 @@ after_success: #env (need to copy settings from above) +# before_script From d6c248e96e48c8f48b2b81641f3f88f6d7ede8c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sat, 22 Oct 2016 17:56:23 +0200 Subject: [PATCH 03/26] install roxygen2 only if needed --- .travis.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d0ac2f7..3985e6a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -28,6 +28,9 @@ matrix: r_github_packages: - krlmlr/pkgdown@develop - krlmlr/travis@develop + r_packages: + - covr + - roxygen2 - r: devel - os: osx osx_image: xcode7.2 @@ -37,7 +40,6 @@ matrix: #r_packages r_packages: - covr - - roxygen2 #notifications notifications: @@ -54,7 +56,7 @@ after_success: #r_github_packages (also need to add to the matrix definition above) -#r_packages (need to copy packages included above) +#r_packages (need to copy packages included above, and add to the matrix definition) #env (need to copy settings from above) From 09a213adc6b79bb81623b985cbeda74d4513558f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sat, 22 Oct 2016 17:57:36 +0200 Subject: [PATCH 04/26] comment --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3985e6a..7692aa2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ addons: - libmagick++-dev - libssh2-1-dev -# OS X (R release only) +# Matrix: 3x Linux, 1x OS X matrix: include: - r: oldrel From db8d13b3c9cb62ca689b7415b6462289f2de533e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 23 Oct 2016 08:23:44 +0200 Subject: [PATCH 05/26] oops --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 7692aa2..76d76c2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -50,7 +50,7 @@ notifications: #after_success (deploy to gh-pages and run covr) after_success: - scripts/deploy-pages.sh - - R -e 'covr::codecov()'; fi + - R -e 'covr::codecov()' # Custom parts: From cc63bf79acec3c69daa8452c6e8f405198b8079d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 23 Oct 2016 08:23:49 +0200 Subject: [PATCH 06/26] harmonize --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 76d76c2..62b8604 100644 --- a/.travis.yml +++ b/.travis.yml @@ -60,4 +60,8 @@ after_success: #env (need to copy settings from above) +# services + +#before_install + # before_script From 07175f5699bef3e77bcba571bfc851cf8292b3e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 23 Oct 2016 08:43:41 +0200 Subject: [PATCH 07/26] doc --- R/file.R | 5 +++-- man/find_root_file.Rd | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/R/file.R b/R/file.R index 6125506..a1e44bb 100644 --- a/R/file.R +++ b/R/file.R @@ -11,8 +11,9 @@ #' @param criterion A criterion, will be coerced using #' \code{\link{as.root_criterion}} #' @param path The start directory -#' @param ... Additional arguments passed to \code{\link{file.path}} -#' @return The normalized path of the root as specified by the search criteria. +#' @param ... Further path components passed to \code{\link{file.path}} +#' @return The normalized path of the root as specified by the search criteria, +#' with the additional path components appended. #' Throws an error if no root is found #' #' @examples diff --git a/man/find_root_file.Rd b/man/find_root_file.Rd index 54ced59..0b118a3 100644 --- a/man/find_root_file.Rd +++ b/man/find_root_file.Rd @@ -13,7 +13,7 @@ find_rstudio_root_file(..., path = ".") find_package_root_file(..., path = ".") } \arguments{ -\item{...}{Additional arguments passed to \code{\link{file.path}}} +\item{...}{Further path components passed to \code{\link{file.path}}} \item{criterion}{A criterion, will be coerced using \code{\link{as.root_criterion}}} @@ -21,7 +21,8 @@ find_package_root_file(..., path = ".") \item{path}{The start directory} } \value{ -The normalized path of the root as specified by the search criteria. +The normalized path of the root as specified by the search criteria, + with the additional path components appended. Throws an error if no root is found } \description{ From 8064aa2a4717d03afa2b38b773e37856fb81ed36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 23 Oct 2016 08:42:46 +0200 Subject: [PATCH 08/26] is_remake_project and find_remake_root_file() - New `is_remake_project` and `find_remake_root_file()` (#17). --- NAMESPACE | 2 ++ R/has-file.R | 11 +++++++++++ R/shortcut.R | 4 ++++ man/criteria.Rd | 7 ++++++- man/find_root_file.Rd | 3 +++ 5 files changed, 26 insertions(+), 1 deletion(-) diff --git a/NAMESPACE b/NAMESPACE index 876c516..641c1e4 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -10,6 +10,7 @@ S3method(str,root_criteria) export(as.root_criterion) export(criteria) export(find_package_root_file) +export(find_remake_root_file) export(find_root) export(find_root_file) export(find_rstudio_root_file) @@ -18,6 +19,7 @@ export(has_file) export(has_file_pattern) export(is.root_criterion) export(is_r_package) +export(is_remake_project) export(is_rstudio_project) export(root_criterion) importFrom(utils,str) diff --git a/R/has-file.R b/R/has-file.R index 9a5cbd1..86b246b 100644 --- a/R/has-file.R +++ b/R/has-file.R @@ -72,6 +72,9 @@ is_rstudio_project <- has_file_pattern("[.]Rproj$", contents = "^Version: ", n = #' @export is_r_package <- has_file("DESCRIPTION", contents = "^Package: ") +#' @export +is_remake_project <- has_file("remake.yml") + #' @export from_wd <- root_criterion(function(path) TRUE, "From current working directory") @@ -84,6 +87,7 @@ criteria <- structure( list( is_rstudio_project = is_rstudio_project, is_r_package = is_r_package, + is_remake_project = is_remake_project, from_wd = from_wd ), class = "root_criteria") @@ -108,6 +112,13 @@ str.root_criteria <- function(object, ...) { #' @export "is_r_package" +#' @details +#' \code{is_remake_project} looks for a \code{remake.yml} file. +#' +#' @rdname criteria +#' @export +"is_remake_project" + #' @details #' \code{from_wd} uses the current working directory. #' diff --git a/R/shortcut.R b/R/shortcut.R index 08d5cba..ede6974 100644 --- a/R/shortcut.R +++ b/R/shortcut.R @@ -5,3 +5,7 @@ find_rstudio_root_file <- is_rstudio_project$find_file #' @rdname find_root_file #' @export find_package_root_file <- is_r_package$find_file + +#' @rdname find_root_file +#' @export +find_remake_root_file <- is_remake_project$find_file diff --git a/man/criteria.Rd b/man/criteria.Rd index d6db9d3..c8ba458 100644 --- a/man/criteria.Rd +++ b/man/criteria.Rd @@ -5,9 +5,10 @@ \alias{criteria} \alias{from_wd} \alias{is_r_package} +\alias{is_remake_project} \alias{is_rstudio_project} \title{Prespecified criteria} -\format{An object of class \code{root_criteria} of length 3.} +\format{An object of class \code{root_criteria} of length 4.} \usage{ criteria @@ -15,6 +16,8 @@ is_rstudio_project is_r_package +is_remake_project + from_wd } \description{ @@ -25,6 +28,8 @@ This is a collection of commonly used root criteria. \code{is_r_package} looks for a \code{DESCRIPTION} file. +\code{is_remake_project} looks for a \code{remake.yml} file. + \code{from_wd} uses the current working directory. } \keyword{datasets} diff --git a/man/find_root_file.Rd b/man/find_root_file.Rd index 0b118a3..2adcb35 100644 --- a/man/find_root_file.Rd +++ b/man/find_root_file.Rd @@ -2,6 +2,7 @@ % Please edit documentation in R/file.R, R/shortcut.R \name{find_root_file} \alias{find_package_root_file} +\alias{find_remake_root_file} \alias{find_root_file} \alias{find_rstudio_root_file} \title{File paths relative to the root of a directory hierarchy} @@ -11,6 +12,8 @@ find_root_file(..., criterion, path = ".") find_rstudio_root_file(..., path = ".") find_package_root_file(..., path = ".") + +find_remake_root_file(..., path = ".") } \arguments{ \item{...}{Further path components passed to \code{\link{file.path}}} From 7702c8e9b111d6521c789d929fae7d4c198468f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 23 Oct 2016 10:06:45 +0200 Subject: [PATCH 09/26] import backports --- DESCRIPTION | 2 ++ NAMESPACE | 1 + R/rprojroot-package.R | 1 + 3 files changed, 4 insertions(+) diff --git a/DESCRIPTION b/DESCRIPTION index 8a2e982..99777e2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -9,6 +9,8 @@ Description: Robust, reliable and flexible paths to files below a regular file. Depends: R (>= 3.0.0) +Imports: + backports Suggests: testthat, knitr, diff --git a/NAMESPACE b/NAMESPACE index 641c1e4..3b552d0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -22,4 +22,5 @@ export(is_r_package) export(is_remake_project) export(is_rstudio_project) export(root_criterion) +import(backports) importFrom(utils,str) diff --git a/R/rprojroot-package.R b/R/rprojroot-package.R index 6b14ed9..47b947e 100644 --- a/R/rprojroot-package.R +++ b/R/rprojroot-package.R @@ -8,4 +8,5 @@ #' is_r_package$find_file("NAMESPACE") #' root_fun <- is_r_package$make_fix_file() #' root_fun("NAMESPACE") +#' @import backports "_PACKAGE" From ccb44e75167eda219077a04a05066eb7db90c57a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 23 Oct 2016 10:06:54 +0200 Subject: [PATCH 10/26] use dir.exists() instead of file.info() --- R/has-file.R | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/R/has-file.R b/R/has-file.R index 86b246b..56a77e9 100644 --- a/R/has-file.R +++ b/R/has-file.R @@ -135,10 +135,7 @@ list_files <- function(path, filename) { } is_dir <- function(x) { - if (getRversion() >= "3.2") - file.info(x, extra_cols = FALSE)$isdir - else - file.info(x)$isdir + dir.exists(x) } match_contents <- function(f, contents, n) { From 23d7378ea7ef61ea75049365bb53d01bcae60a75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 23 Oct 2016 12:39:18 +0200 Subject: [PATCH 11/26] better navbar --- README.md | 2 +- _pkgdown.yml | 9 +++++++++ readme/README.Rmd | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7445f36..55489fc 100644 --- a/README.md +++ b/README.md @@ -35,4 +35,4 @@ Install from GitHub: devtools::install_github("krlmlr/rprojroot") ``` -See the [vignette](http://krlmlr.github.io/rprojroot/vignettes/rprojroot.html) for more detail. +See the [documentation](http://krlmlr.github.io/rprojroot/articles/rprojroot.html) for more detail. diff --git a/_pkgdown.yml b/_pkgdown.yml index 1303a74..b042bb4 100644 --- a/_pkgdown.yml +++ b/_pkgdown.yml @@ -1,3 +1,12 @@ template: bootswatch: flatly # https://bootswatch.com/flatly/ +navbar: + type: default + left: + - text: Documentation + href: articles/rprojroot.html + - text: Reference + href: reference/index.html + - text: News + href: news/index.html diff --git a/readme/README.Rmd b/readme/README.Rmd index d162657..b51fcc4 100644 --- a/readme/README.Rmd +++ b/readme/README.Rmd @@ -46,4 +46,4 @@ Install from GitHub: devtools::install_github("krlmlr/rprojroot") ``` -See the [vignette](http://krlmlr.github.io/rprojroot/vignettes/rprojroot.html) for more detail. +See the [documentation](http://krlmlr.github.io/rprojroot/articles/rprojroot.html) for more detail. From 623f1eb8012692055a1e056e8a130884539341e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 23 Oct 2016 10:03:18 +0200 Subject: [PATCH 12/26] criterion$subdir --- R/criterion.R | 7 +++++-- R/root.R | 16 ++++++++++++++-- man/root_criterion.Rd | 5 ++++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/R/criterion.R b/R/criterion.R index 95b382e..a77fd67 100644 --- a/R/criterion.R +++ b/R/criterion.R @@ -10,6 +10,7 @@ #' if the directory specified by this parameter is the project root, #' and \code{FALSE} otherwise #' @param desc A textual description of the test criterion +#' @param subdir Subdirectories to start the search in, if found #' #' @return #' An S3 object of class \code{root_criterion} wit the following members: @@ -25,7 +26,7 @@ #' \dontrun{ #' is_r_package$make_fix_file(".") #' } -root_criterion <- function(testfun, desc) { +root_criterion <- function(testfun, desc, subdir = NULL) { if (!isTRUE(all.equal(names(formals(testfun)), "path"))) { stop("testfun must be a function with one argument 'path'") } @@ -36,7 +37,9 @@ root_criterion <- function(testfun, desc) { #' \item{\code{testfun}}{The \code{testfun} argument} testfun = testfun, #' \item{\code{desc}}{The \code{desc} argument} - desc = desc + desc = desc, + #' \item{\code{subdir}}{The \code{subdir} argument} + subdir = subdir ), class = "root_criterion" ) diff --git a/R/root.R b/R/root.R index c02c980..d52a332 100644 --- a/R/root.R +++ b/R/root.R @@ -26,8 +26,7 @@ find_root <- function(criterion, path = ".") { criterion <- as.root_criterion(criterion) - original_path <- path - path <- normalizePath(path, winslash = "/", mustWork = TRUE) + path <- start_path(path, criterion$subdir) for (i in seq_len(.MAX_DEPTH)) { if (criterion$testfun(path)) { @@ -47,6 +46,19 @@ find_root <- function(criterion, path = ".") { .MAX_DEPTH <- 100L +start_path <- function(path, subdirs) { + path <- normalizePath(path, winslash = "/", mustWork = TRUE) + + for (subdir in subdirs) { + subdir_path <- file.path(path, subdir) + if (dir.exists(subdir_path)) { + return(subdir_path) + } + } + + path +} + # Borrowed from devtools is_root <- function(path) { identical(normalizePath(path, winslash = "/"), diff --git a/man/root_criterion.Rd b/man/root_criterion.Rd index c26c37b..50ddd98 100644 --- a/man/root_criterion.Rd +++ b/man/root_criterion.Rd @@ -10,7 +10,7 @@ \alias{root_criterion} \title{Is a directory the project root?} \usage{ -root_criterion(testfun, desc) +root_criterion(testfun, desc, subdir = NULL) is.root_criterion(x) @@ -31,6 +31,8 @@ and \code{FALSE} otherwise} \item{desc}{A textual description of the test criterion} +\item{subdir}{Subdirectories to start the search in, if found} + \item{x}{An object} \item{filepath}{File path (can contain directories)} @@ -49,6 +51,7 @@ An S3 object of class \code{root_criterion} wit the following members: \describe{ \item{\code{testfun}}{The \code{testfun} argument} \item{\code{desc}}{The \code{desc} argument} + \item{\code{subdir}}{The \code{subdir} argument} \item{\code{find_file}}{A function with \code{...} argument that returns for a path relative to the root specified by this criterion. The optional \code{path} argument specifies the starting directory, From c4a8173033c4b5f86132e8e338fa71181713664b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 23 Oct 2016 10:12:18 +0200 Subject: [PATCH 13/26] has_dirname() --- NAMESPACE | 1 + R/has-file.R | 19 +++++++++++++++++++ man/root_criterion.Rd | 8 ++++++++ 3 files changed, 28 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index 3b552d0..0b3ead2 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -15,6 +15,7 @@ export(find_root) export(find_root_file) export(find_rstudio_root_file) export(from_wd) +export(has_dirname) export(has_file) export(has_file_pattern) export(is.root_criterion) diff --git a/R/has-file.R b/R/has-file.R index 56a77e9..49e5afe 100644 --- a/R/has-file.R +++ b/R/has-file.R @@ -66,6 +66,25 @@ has_file_pattern <- function(pattern, contents = NULL, n = -1L) { root_criterion(testfun, desc) } +#' @details +#' The \code{has_dirname} function constructs a criterion that checks if the +#' \code{\link[base]{dirname}} has a specific name. +#' +#' @rdname root_criterion +#' @param dirname A directory name, without subdirectories +#' @export +has_dirname <- function(dirname, subdir = NULL) { + force(dirname) + + testfun <- eval(bquote(function(path) { + dir.exists(file.path(basename(dirname(path)), .(dirname))) + })) + + desc <- paste0("Directory name is '", dirname, "'") + + root_criterion(testfun, desc, subdir = subdir) +} + #' @export is_rstudio_project <- has_file_pattern("[.]Rproj$", contents = "^Version: ", n = 1L) diff --git a/man/root_criterion.Rd b/man/root_criterion.Rd index 50ddd98..1320e93 100644 --- a/man/root_criterion.Rd +++ b/man/root_criterion.Rd @@ -4,6 +4,7 @@ \alias{as.root_criterion} \alias{as.root_criterion.character} \alias{as.root_criterion.root_criterion} +\alias{has_dirname} \alias{has_file} \alias{has_file_pattern} \alias{is.root_criterion} @@ -23,6 +24,8 @@ as.root_criterion(x) has_file(filepath, contents = NULL, n = -1L) has_file_pattern(pattern, contents = NULL, n = -1L) + +has_dirname(dirname, subdir = NULL) } \arguments{ \item{testfun}{A function with one parameter that returns \code{TRUE} @@ -44,6 +47,8 @@ and \code{FALSE} otherwise} input on the connection.} \item{pattern}{Regular expression to match the file name} + +\item{dirname}{A directory name, without subdirectories} } \value{ An S3 object of class \code{root_criterion} wit the following members: @@ -84,6 +89,9 @@ root) with specific contents. The \code{has_file_pattern} function constructs a criterion that checks for the existence of a file that matches a pattern, with specific contents. + +The \code{has_dirname} function constructs a criterion that checks if the +\code{\link[base]{dirname}} has a specific name. } \examples{ root_criterion(function(path) file.exists(file.path(path, "somefile")), "Has somefile") From 6e758346189e30087b4997dec09875d1bbf5f973 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 23 Oct 2016 10:19:00 +0200 Subject: [PATCH 14/26] criterion desc contains subdirectory --- R/criterion.R | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/R/criterion.R b/R/criterion.R index a77fd67..0a1fe7f 100644 --- a/R/criterion.R +++ b/R/criterion.R @@ -30,6 +30,16 @@ root_criterion <- function(testfun, desc, subdir = NULL) { if (!isTRUE(all.equal(names(formals(testfun)), "path"))) { stop("testfun must be a function with one argument 'path'") } + + full_desc <- paste0( + desc, + if (!is.null(subdir)) paste0( + " (also look in subdirectories: ", + paste(subdir, collapse = ", "), + ")" + ) + ) + criterion <- structure( list( #' @return @@ -37,7 +47,7 @@ root_criterion <- function(testfun, desc, subdir = NULL) { #' \item{\code{testfun}}{The \code{testfun} argument} testfun = testfun, #' \item{\code{desc}}{The \code{desc} argument} - desc = desc, + desc = full_desc, #' \item{\code{subdir}}{The \code{subdir} argument} subdir = subdir ), From 9b89409b95c909c153cd21902bda748f04c4aa2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 23 Oct 2016 10:19:36 +0200 Subject: [PATCH 15/26] is_testthat --- NAMESPACE | 1 + R/has-file.R | 12 ++++++++++++ man/criteria.Rd | 8 +++++++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/NAMESPACE b/NAMESPACE index 0b3ead2..8c40cab 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -22,6 +22,7 @@ export(is.root_criterion) export(is_r_package) export(is_remake_project) export(is_rstudio_project) +export(is_testthat) export(root_criterion) import(backports) importFrom(utils,str) diff --git a/R/has-file.R b/R/has-file.R index 49e5afe..3cc2f55 100644 --- a/R/has-file.R +++ b/R/has-file.R @@ -97,6 +97,9 @@ is_remake_project <- has_file("remake.yml") #' @export from_wd <- root_criterion(function(path) TRUE, "From current working directory") +#' @export +is_testthat <- has_dirname("testthat", c("tests/testthat", "testthat")) + #' Prespecified criteria #' #' This is a collection of commonly used root criteria. @@ -107,6 +110,7 @@ criteria <- structure( is_rstudio_project = is_rstudio_project, is_r_package = is_r_package, is_remake_project = is_remake_project, + is_testthat = is_testthat, from_wd = from_wd ), class = "root_criteria") @@ -138,6 +142,14 @@ str.root_criteria <- function(object, ...) { #' @export "is_remake_project" +#' @details +#' \code{is_testthat} looks for the \code{testthat} directory, works when +#' developing, testing, and checking a package. +#' +#' @rdname criteria +#' @export +"is_testthat" + #' @details #' \code{from_wd} uses the current working directory. #' diff --git a/man/criteria.Rd b/man/criteria.Rd index c8ba458..a2e096c 100644 --- a/man/criteria.Rd +++ b/man/criteria.Rd @@ -7,8 +7,9 @@ \alias{is_r_package} \alias{is_remake_project} \alias{is_rstudio_project} +\alias{is_testthat} \title{Prespecified criteria} -\format{An object of class \code{root_criteria} of length 4.} +\format{An object of class \code{root_criteria} of length 5.} \usage{ criteria @@ -18,6 +19,8 @@ is_r_package is_remake_project +is_testthat + from_wd } \description{ @@ -30,6 +33,9 @@ This is a collection of commonly used root criteria. \code{is_remake_project} looks for a \code{remake.yml} file. +\code{is_testthat} looks for the \code{testthat} directory, works when + developing, testing, and checking a package. + \code{from_wd} uses the current working directory. } \keyword{datasets} From 2cf9b309115b7345c5aee08f70670a99f8be0113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 23 Oct 2016 10:49:24 +0200 Subject: [PATCH 16/26] tests --- tests/testthat/test-root.R | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tests/testthat/test-root.R b/tests/testthat/test-root.R index df694e5..da39969 100644 --- a/tests/testthat/test-root.R +++ b/tests/testthat/test-root.R @@ -63,8 +63,42 @@ test_that("has_file_pattern", { ) }) +test_that("has_dirname", { + wd <- normalizePath(getwd(), winslash = "/") + hierarchy <- function(n = 0L) { + do.call(file.path, list(wd, "hierarchy", "a", "b", "c")[seq_len(n + 1L)]) + } + + stop_path <- hierarchy(1L) + path <- hierarchy(4L) + + with_mock( + `rprojroot:::is_root` = function(x) x == stop_path, + expect_equal(find_root(has_dirname("a"), path = path), hierarchy(2L)), + expect_equal(find_root(has_dirname("b"), path = path), hierarchy(3L)), + expect_equal(find_root_file("c", criterion = has_dirname("b"), path = path), + file.path(hierarchy(3L), "c")), + expect_equal(find_root(has_dirname("c"), path = path), hierarchy(4L)), + expect_error(find_root(has_dirname("d"), path = path), + "No root directory found.* is '.*'"), + expect_error(find_root(has_dirname("rprojroot.Rproj"), path = path), + "No root directory found.* is '.*'"), + TRUE + ) +}) + test_that("finds root", { skip_on_cran() # Checks that search for root actually terminates expect_error(find_root("/"), "No root directory found.* file '.*'") }) + +test_that("stops if depth reached", { + find_root_mocked <- find_root + mock_env <- new.env() + mock_env$dirname <- identity + environment(find_root_mocked) <- mock_env + + # Checks that search for root terminates for very deep hierarchies + expect_error(find_root_mocked(""), "Maximum search of [0-9]+ exceeded") +}) From c9d8062ca3c33d765237f944675ec707c99643e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 23 Oct 2016 10:49:28 +0200 Subject: [PATCH 17/26] oops --- R/has-file.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/has-file.R b/R/has-file.R index 3cc2f55..04f1bfe 100644 --- a/R/has-file.R +++ b/R/has-file.R @@ -77,7 +77,7 @@ has_dirname <- function(dirname, subdir = NULL) { force(dirname) testfun <- eval(bquote(function(path) { - dir.exists(file.path(basename(dirname(path)), .(dirname))) + dir.exists(file.path(dirname(path), .(dirname))) })) desc <- paste0("Directory name is '", dirname, "'") From 4e9eeb00499f452924711aefea7702f230654ca8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 23 Oct 2016 10:54:31 +0200 Subject: [PATCH 18/26] is_testthat formatting --- R/criterion.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/criterion.R b/R/criterion.R index 0a1fe7f..3af337b 100644 --- a/R/criterion.R +++ b/R/criterion.R @@ -35,7 +35,7 @@ root_criterion <- function(testfun, desc, subdir = NULL) { desc, if (!is.null(subdir)) paste0( " (also look in subdirectories: ", - paste(subdir, collapse = ", "), + paste0("'", subdir, "'", collapse = ", "), ")" ) ) From 7ce9c6cacda32dc09279f0e95dda6db5e6746d51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 23 Oct 2016 10:54:34 +0200 Subject: [PATCH 19/26] tests --- tests/testthat/package/DESCRIPTION | 0 tests/testthat/package/tests/testthat.R | 0 tests/testthat/package/tests/testthat/.gitignore | 0 tests/testthat/test-testthat.R | 10 ++++++++++ 4 files changed, 10 insertions(+) create mode 100644 tests/testthat/package/DESCRIPTION create mode 100644 tests/testthat/package/tests/testthat.R create mode 100644 tests/testthat/package/tests/testthat/.gitignore create mode 100644 tests/testthat/test-testthat.R diff --git a/tests/testthat/package/DESCRIPTION b/tests/testthat/package/DESCRIPTION new file mode 100644 index 0000000..e69de29 diff --git a/tests/testthat/package/tests/testthat.R b/tests/testthat/package/tests/testthat.R new file mode 100644 index 0000000..e69de29 diff --git a/tests/testthat/package/tests/testthat/.gitignore b/tests/testthat/package/tests/testthat/.gitignore new file mode 100644 index 0000000..e69de29 diff --git a/tests/testthat/test-testthat.R b/tests/testthat/test-testthat.R new file mode 100644 index 0000000..473b57c --- /dev/null +++ b/tests/testthat/test-testthat.R @@ -0,0 +1,10 @@ +context("testthat") + +test_that("is_testthat", { + expect_match(format(is_testthat), "^.*Directory name is 'testthat' .* subdirectories.*'tests/testthat'.*'testthat'.*$") + + testthat_path <- normalizePath("package/tests/testthat", winslash = "/") + expect_equal(is_testthat$find_file(path = "package"), testthat_path) + expect_equal(is_testthat$find_file(path = "package/tests"), testthat_path) + expect_equal(is_testthat$find_file(path = "package/tests/testthat"), testthat_path) +}) From 16adfd0c8b46a3e87058a789046b8e9adc6db13f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 23 Oct 2016 12:46:54 +0200 Subject: [PATCH 20/26] make checkable --- R/rprojroot-package.R | 2 ++ man/rprojroot-package.Rd | 2 ++ tests/testthat/test-criterion.R | 2 ++ 3 files changed, 6 insertions(+) diff --git a/R/rprojroot-package.R b/R/rprojroot-package.R index 47b947e..8f38d4f 100644 --- a/R/rprojroot-package.R +++ b/R/rprojroot-package.R @@ -5,8 +5,10 @@ #' #' @examples #' criteria +#' \dontrun{ #' is_r_package$find_file("NAMESPACE") #' root_fun <- is_r_package$make_fix_file() #' root_fun("NAMESPACE") +#' } #' @import backports "_PACKAGE" diff --git a/man/rprojroot-package.Rd b/man/rprojroot-package.Rd index c6801f8..ce42a68 100644 --- a/man/rprojroot-package.Rd +++ b/man/rprojroot-package.Rd @@ -18,8 +18,10 @@ root criteria. } \examples{ criteria +\dontrun{ is_r_package$find_file("NAMESPACE") root_fun <- is_r_package$make_fix_file() root_fun("NAMESPACE") } +} diff --git a/tests/testthat/test-criterion.R b/tests/testthat/test-criterion.R index 90be437..f1573b7 100644 --- a/tests/testthat/test-criterion.R +++ b/tests/testthat/test-criterion.R @@ -34,6 +34,8 @@ test_that("Formatting criteria", { }) test_that("Combining criteria", { + skip_on_cran() + comb_crit <- is_r_package | is_rstudio_project expect_true(is.root_criterion(comb_crit)) From 658babf92793596c1585f375c555305cecdf42bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 23 Oct 2016 12:47:01 +0200 Subject: [PATCH 21/26] dogfood --- tests/testthat/test-testthat.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/testthat/test-testthat.R b/tests/testthat/test-testthat.R index 473b57c..0553586 100644 --- a/tests/testthat/test-testthat.R +++ b/tests/testthat/test-testthat.R @@ -8,3 +8,7 @@ test_that("is_testthat", { expect_equal(is_testthat$find_file(path = "package/tests"), testthat_path) expect_equal(is_testthat$find_file(path = "package/tests/testthat"), testthat_path) }) + +test_that("dogfood", { + expect_true(file.exists(is_testthat$find_file("hierarchy", "a", "b", "c", "d"))) +}) From ccccbfcc03a30965652e16464b7242a4de730da0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 23 Oct 2016 12:55:04 +0200 Subject: [PATCH 22/26] doc --- vignettes/rprojroot.Rmd | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/vignettes/rprojroot.Rmd b/vignettes/rprojroot.Rmd index 348a35f..28d725d 100644 --- a/vignettes/rprojroot.Rmd +++ b/vignettes/rprojroot.Rmd @@ -255,6 +255,33 @@ Take a look at the `thisfile()` function in the `kimisc` package for getting the path to the current script or `knitr` document. +## `testthat` files + +Tests run with [`testthat`](https://cran.r-project.org/package=testthat) +commonly use files that live below the `tests/testthat` directory. +Ideally, this should work in the following situation: + +- During package development (working directory: package root) +- When testing with `devtools::test()` (working directory: `tests/testthat`) +- When running `R CMD check` (working directory: a renamed recursive copy of `tests`) + +The `is_testthat` criterion allows robust lookup of test files. + +```{r} +is_testthat +``` + +The example code below lists all files in the +[hierarchy](https://github.com/krlmlr/rprojroot/tree/master/tests/testthat/hierarchy) +test directory. +It uses two project root lookups in total, +so that it also works when rendering the vignette (*sigh*): + +```{r} +dir(is_testthat$find_file("hierarchy", path = is_r_package$find_file())) +``` + + ## Summary The `rprojroot` package allows easy access to files below a project root From 75e1658d82fd4bb5c4dc4e593b90a26ee5b82552 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 23 Oct 2016 22:31:26 +0200 Subject: [PATCH 23/26] need file to pass R CMD check --- tests/testthat/package/tests/testthat/test-something.R | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/testthat/package/tests/testthat/test-something.R diff --git a/tests/testthat/package/tests/testthat/test-something.R b/tests/testthat/package/tests/testthat/test-something.R new file mode 100644 index 0000000..e69de29 From 766b5cef55dbdf041edad3eb2580907c6c09a2a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 23 Oct 2016 23:06:33 +0200 Subject: [PATCH 24/26] new find_testthat_root_file `find_testthat_root_file` --- NAMESPACE | 1 + R/shortcut.R | 4 ++++ man/find_root_file.Rd | 3 +++ 3 files changed, 8 insertions(+) diff --git a/NAMESPACE b/NAMESPACE index 8c40cab..1773a49 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -14,6 +14,7 @@ export(find_remake_root_file) export(find_root) export(find_root_file) export(find_rstudio_root_file) +export(find_testthat_root_file) export(from_wd) export(has_dirname) export(has_file) diff --git a/R/shortcut.R b/R/shortcut.R index ede6974..8cdb366 100644 --- a/R/shortcut.R +++ b/R/shortcut.R @@ -9,3 +9,7 @@ find_package_root_file <- is_r_package$find_file #' @rdname find_root_file #' @export find_remake_root_file <- is_remake_project$find_file + +#' @rdname find_root_file +#' @export +find_testthat_root_file <- is_testthat$find_file diff --git a/man/find_root_file.Rd b/man/find_root_file.Rd index 2adcb35..9a1a706 100644 --- a/man/find_root_file.Rd +++ b/man/find_root_file.Rd @@ -5,6 +5,7 @@ \alias{find_remake_root_file} \alias{find_root_file} \alias{find_rstudio_root_file} +\alias{find_testthat_root_file} \title{File paths relative to the root of a directory hierarchy} \usage{ find_root_file(..., criterion, path = ".") @@ -14,6 +15,8 @@ find_rstudio_root_file(..., path = ".") find_package_root_file(..., path = ".") find_remake_root_file(..., path = ".") + +find_testthat_root_file(..., path = ".") } \arguments{ \item{...}{Further path components passed to \code{\link{file.path}}} From 9a058a6c02f94193f8eab0bee80e9cf7fc722e0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 23 Oct 2016 23:06:46 +0200 Subject: [PATCH 25/26] bump version to 1.0-7 --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 99777e2..1706ae1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: rprojroot Title: Finding Files in Project Subdirectories -Version: 1.0-6 +Version: 1.0-7 Authors@R: person(given = "Kirill", family = "Müller", role = c("aut", "cre"), email = "krlmlr+r@mailbox.org") Description: Robust, reliable and flexible paths to files below a From 7f358fcce3232fe65239cc096825f60d2e0150ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kirill=20M=C3=BCller?= Date: Sun, 23 Oct 2016 23:07:49 +0200 Subject: [PATCH 26/26] NEWS --- NEWS.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/NEWS.md b/NEWS.md index 11e092f..9b8bb4a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,11 @@ +## rprojroot 1.0-7 (2016-10-23) + +- New `is_testthat` and `find_testthat_root_file()` that looks for `tests/testthat` root (#14). +- Improve navbar on project page. +- Uses `backports` to simplify compatibility with R 3.0.0. +- New `is_remake_project` and `find_remake_root_file()` that looks for remate project (#17). + + ## rprojroot 1.0-6 (2016-10-22) - Travis tests three R versions, and OS X.