Skip to content

Commit 662a7c1

Browse files
committed
Merge branch 'r-1.2' into production
2 parents d35f0dc + 40b57ed commit 662a7c1

35 files changed

+750
-171
lines changed

.Rbuildignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
^.*\.Rproj$
1+
^rprojroot\.Rproj$
22
^\.Rproj\.user$
33
^\.gitignore$
44
^README\.md$
@@ -20,3 +20,5 @@
2020
^_pkgdown\.yml$
2121
^revdep$
2222
^tic\.R$
23+
^tests/testthat/hierarchy/a/b/\.projectile$
24+
^API$

.deploy_key.enc

-1.67 KB
Binary file not shown.

.deploy_key.pub

Lines changed: 0 additions & 10 deletions
This file was deleted.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ inst/doc
55
/docs/
66
/vignettes/*.html
77
/revdep/.cache.rds
8+
.projectile

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Header
44
language: r
55
sudo: false
6+
dist: trusty
67
cache: packages
78
warnings_are_errors: true
89

API

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# API for rprojroot package
2+
3+
## Exported functions
4+
5+
as.root_criterion(x)
6+
find_package_root_file(..., path = ".")
7+
find_remake_root_file(..., path = ".")
8+
find_root(criterion, path = ".")
9+
find_root_file(..., criterion, path = ".")
10+
find_rstudio_root_file(..., path = ".")
11+
find_testthat_root_file(..., path = ".")
12+
get_root_desc(criterion, path)
13+
has_dir(filepath)
14+
has_dirname(dirname, subdir = NULL)
15+
has_file(filepath, contents = NULL, n = -1L)
16+
has_file_pattern(pattern, contents = NULL, n = -1L)
17+
is.root_criterion(x)
18+
root_criterion(testfun, desc, subdir = NULL)
19+
20+
## S3 methods
21+
22+
as.root_criterion.character(x)
23+
as.root_criterion.default(x)
24+
as.root_criterion.root_criterion(x)
25+
26+
## Exported data
27+
28+
criteria: root_criteria (list[9])
29+
from_wd: root_criterion (list[5])
30+
is_git_root: root_criterion (list[5])
31+
is_projectile_project: root_criterion (list[5])
32+
is_r_package: root_criterion (list[5])
33+
is_remake_project: root_criterion (list[5])
34+
is_rstudio_project: root_criterion (list[5])
35+
is_svn_root: root_criterion (list[5])
36+
is_testthat: root_criterion (list[5])
37+
is_vcs_root: root_criterion (list[5])

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: rprojroot
22
Title: Finding Files in Project Subdirectories
3-
Version: 1.1
3+
Version: 1.2
44
Authors@R: person(given = "Kirill", family = "Müller", role = c("aut",
55
"cre"), email = "krlmlr+r@mailbox.org")
66
Description: Robust, reliable and flexible paths to files below a
@@ -31,3 +31,4 @@ Collate:
3131
'root.R'
3232
'rprojroot-package.R'
3333
'shortcut.R'
34+
Roxygen: list(markdown = TRUE)

NAMESPACE

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,20 @@ export(find_root_file)
1616
export(find_rstudio_root_file)
1717
export(find_testthat_root_file)
1818
export(from_wd)
19+
export(get_root_desc)
20+
export(has_dir)
1921
export(has_dirname)
2022
export(has_file)
2123
export(has_file_pattern)
2224
export(is.root_criterion)
25+
export(is_git_root)
26+
export(is_projectile_project)
2327
export(is_r_package)
2428
export(is_remake_project)
2529
export(is_rstudio_project)
30+
export(is_svn_root)
2631
export(is_testthat)
32+
export(is_vcs_root)
2733
export(root_criterion)
2834
import(backports)
2935
importFrom(utils,str)

NEWS.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
# rprojroot 1.2 (2017-01-15)
2+
3+
- New root criteria
4+
- `is_projectile_project` recognize projectile projects (#21).
5+
- `has_dir()` constructs root criteria that check for existence of a directory.
6+
- `is_git_root`, `is_svn_root` and `is_vcs_root` look for a version control system root (#19).
7+
8+
- New function
9+
- `get_root_desc()` returns the description of the criterion that applies to a given root, useful for composite criteria created with `|`.
10+
11+
- Minor enhancements
12+
- Improve formatting of alternative criteria (#18).
13+
- If root cannot be found, the start path is shown in the error message.
14+
15+
- Internal
16+
- The `$testfun` member of the `rprojroot` S3 class is now a list of functions instead of a function.
17+
18+
119
# rprojroot 1.1 (2016-10-29)
220

321
- Compatibility

R/criterion.R

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,42 @@
11
#' Is a directory the project root?
22
#'
3-
#' Objects of the \code{root_criterion} class decide if a
3+
#' Objects of the `root_criterion` class decide if a
44
#' given directory is a project root.
55
#'
6-
#' Construct criteria using \code{root_criterion} in a very general fashion
7-
#' by specifying a function with a \code{path} argument, and a description.
6+
#' Construct criteria using `root_criterion` in a very general fashion
7+
#' by specifying a function with a `path` argument, and a description.
88
#'
9-
#' @param testfun A function with one parameter that returns \code{TRUE}
9+
#' @param testfun A function with one parameter that returns `TRUE`
1010
#' if the directory specified by this parameter is the project root,
11-
#' and \code{FALSE} otherwise
12-
#' @param desc A textual description of the test criterion
11+
#' and `FALSE` otherwise. Can also be a list of such functions.
12+
#' @param desc A textual description of the test criterion, of the same length
13+
#' as `testfun`
1314
#' @param subdir Subdirectories to start the search in, if found
1415
#'
1516
#' @return
16-
#' An S3 object of class \code{root_criterion} wit the following members:
17+
#' An S3 object of class `root_criterion` wit the following members:
1718
#'
1819
#' @include rrmake.R
1920
#' @export
2021
#'
2122
#' @examples
22-
#' root_criterion(function(path) file.exists(file.path(path, "somefile")), "Has somefile")
23+
#' root_criterion(function(path) file.exists(file.path(path, "somefile")), "has somefile")
2324
#' has_file("DESCRIPTION")
2425
#' is_r_package
2526
#' is_r_package$find_file
2627
#' \dontrun{
2728
#' is_r_package$make_fix_file(".")
2829
#' }
2930
root_criterion <- function(testfun, desc, subdir = NULL) {
30-
if (!isTRUE(all.equal(names(formals(testfun)), "path"))) {
31-
stop("testfun must be a function with one argument 'path'")
32-
}
31+
testfun <- check_testfun(testfun)
32+
33+
stopifnot(length(desc) == length(testfun))
3334

3435
full_desc <- paste0(
3536
desc,
3637
if (!is.null(subdir)) paste0(
3738
" (also look in subdirectories: ",
38-
paste0("'", subdir, "'", collapse = ", "),
39+
paste0("`", subdir, "`", collapse = ", "),
3940
")"
4041
)
4142
)
@@ -44,27 +45,27 @@ root_criterion <- function(testfun, desc, subdir = NULL) {
4445
list(
4546
#' @return
4647
#' \describe{
47-
#' \item{\code{testfun}}{The \code{testfun} argument}
48+
#' \item{`testfun`}{The `testfun` argument}
4849
testfun = testfun,
49-
#' \item{\code{desc}}{The \code{desc} argument}
50+
#' \item{`desc`}{The `desc` argument}
5051
desc = full_desc,
51-
#' \item{\code{subdir}}{The \code{subdir} argument}
52+
#' \item{`subdir`}{The `subdir` argument}
5253
subdir = subdir
5354
),
5455
class = "root_criterion"
5556
)
5657

57-
#' \item{\code{find_file}}{A function with \code{...} argument that returns
58+
#' \item{`find_file`}{A function with `...` argument that returns
5859
#' for a path relative to the root specified by this criterion.
59-
#' The optional \code{path} argument specifies the starting directory,
60-
#' which defaults to \code{"."}.
60+
#' The optional `path` argument specifies the starting directory,
61+
#' which defaults to `"."`.
6162
#' }
6263
criterion$find_file <- make_find_root_file(criterion)
63-
#' \item{\code{make_fix_file}}{A function with a \code{path} argument that
64+
#' \item{`make_fix_file`}{A function with a `path` argument that
6465
#' returns a function that finds paths relative to the root. For a
65-
#' criterion \code{cr}, the result of \code{cr$make_fix_file(".")(...)}
66-
#' is identical to \code{cr$find_file(...)}. The function created by
67-
#' \code{make_fix_file} can be saved to a variable to be more independent
66+
#' criterion `cr`, the result of `cr$make_fix_file(".")(...)`
67+
#' is identical to `cr$find_file(...)`. The function created by
68+
#' `make_fix_file` can be saved to a variable to be more independent
6869
#' of the current working directory.
6970
#' }
7071
#' }
@@ -74,6 +75,20 @@ root_criterion <- function(testfun, desc, subdir = NULL) {
7475
criterion
7576
}
7677

78+
check_testfun <- function(testfun) {
79+
if (is.function(testfun)) {
80+
testfun <- list(testfun)
81+
}
82+
83+
for (f in testfun) {
84+
if (!isTRUE(all.equal(names(formals(f)), "path"))) {
85+
stop("All functions in testfun must have exactly one argument 'path'")
86+
}
87+
}
88+
89+
testfun
90+
}
91+
7792
#' @rdname root_criterion
7893
#' @param x An object
7994
#' @export
@@ -86,9 +101,9 @@ is.root_criterion <- function(x) {
86101
as.root_criterion <- function(x) UseMethod("as.root_criterion", x)
87102

88103
#' @details
89-
#' The \code{as.root_criterion} function accepts objects of class
90-
#' \code{root_criterion}, and character values; the latter will be
91-
#' converted to criteria using \code{has_file}.
104+
#' The `as.root_criterion` function accepts objects of class
105+
#' `root_criterion`, and character values; the latter will be
106+
#' converted to criteria using `has_file`.
92107
#'
93108
#' @rdname root_criterion
94109
#' @export
@@ -107,20 +122,30 @@ as.root_criterion.default <- function(x) {
107122

108123
#' @export
109124
format.root_criterion <- function(x, ...) {
110-
paste("Root criterion:", x$desc)
125+
if (length(x$desc) > 1) {
126+
c("Root criterion: one of", paste0("- ", x$desc))
127+
} else {
128+
paste0("Root criterion: ", x$desc)
129+
}
111130
}
112131

113132
#' @export
114133
print.root_criterion <- function(x, ...) {
115-
cat(paste0(format(x), "\n"))
134+
cat(format(x), sep = "\n")
135+
invisible(x)
116136
}
117137

118138
#' @export
139+
#' @rdname root_criterion
140+
#' @details Root criteria can be combined with the `|` operator. The result is a
141+
#' composite root criterion that requires either of the original criteria to
142+
#' match.
143+
#' @param y An object
119144
`|.root_criterion` <- function(x, y) {
120145
stopifnot(is.root_criterion(y))
121146

122147
root_criterion(
123-
function(path) x$testfun(path) || y$testfun(path),
124-
paste0(x$desc, ", or ", y$desc)
148+
c(x$testfun, y$testfun),
149+
c(x$desc, y$desc)
125150
)
126151
}

0 commit comments

Comments
 (0)