Skip to content

Commit c1123d6

Browse files
committed
Merge branch 'r-1.0-7' into production
2 parents e1b22aa + 7f358fc commit c1123d6

25 files changed

+238
-21
lines changed

.travis.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ addons:
1818
- libmagick++-dev
1919
- libssh2-1-dev
2020

21-
# OS X (R release only)
21+
# Matrix: 3x Linux, 1x OS X
2222
matrix:
2323
include:
2424
- r: oldrel
@@ -28,6 +28,9 @@ matrix:
2828
r_github_packages:
2929
- krlmlr/pkgdown@develop
3030
- krlmlr/travis@develop
31+
r_packages:
32+
- covr
33+
- roxygen2
3134
- r: devel
3235
- os: osx
3336
osx_image: xcode7.2
@@ -37,7 +40,6 @@ matrix:
3740
#r_packages
3841
r_packages:
3942
- covr
40-
- roxygen2
4143

4244
#notifications
4345
notifications:
@@ -48,13 +50,18 @@ notifications:
4850
#after_success (deploy to gh-pages and run covr)
4951
after_success:
5052
- scripts/deploy-pages.sh
51-
- R -e 'covr::codecov()'; fi
53+
- R -e 'covr::codecov()'
5254

5355
# Custom parts:
5456

5557
#r_github_packages (also need to add to the matrix definition above)
5658

57-
#r_packages (need to copy packages included above)
59+
#r_packages (need to copy packages included above, and add to the matrix definition)
5860

5961
#env (need to copy settings from above)
6062

63+
# services
64+
65+
#before_install
66+
67+
# before_script

DESCRIPTION

Lines changed: 3 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.0-6
3+
Version: 1.0-7
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
@@ -9,6 +9,8 @@ Description: Robust, reliable and flexible paths to files below a
99
regular file.
1010
Depends:
1111
R (>= 3.0.0)
12+
Imports:
13+
backports
1214
Suggests:
1315
testthat,
1416
knitr,

NAMESPACE

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,20 @@ S3method(str,root_criteria)
1010
export(as.root_criterion)
1111
export(criteria)
1212
export(find_package_root_file)
13+
export(find_remake_root_file)
1314
export(find_root)
1415
export(find_root_file)
1516
export(find_rstudio_root_file)
17+
export(find_testthat_root_file)
1618
export(from_wd)
19+
export(has_dirname)
1720
export(has_file)
1821
export(has_file_pattern)
1922
export(is.root_criterion)
2023
export(is_r_package)
24+
export(is_remake_project)
2125
export(is_rstudio_project)
26+
export(is_testthat)
2227
export(root_criterion)
28+
import(backports)
2329
importFrom(utils,str)

NEWS.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1+
## rprojroot 1.0-7 (2016-10-23)
2+
3+
- New `is_testthat` and `find_testthat_root_file()` that looks for `tests/testthat` root (#14).
4+
- Improve navbar on project page.
5+
- Uses `backports` to simplify compatibility with R 3.0.0.
6+
- New `is_remake_project` and `find_remake_root_file()` that looks for remate project (#17).
7+
8+
19
## rprojroot 1.0-6 (2016-10-22)
210

311
- Travis tests three R versions, and OS X.
412

13+
514
## rprojroot 1.0-5 (2016-10-22)
615

716
- Use Travis instead of wercker.

R/criterion.R

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#' if the directory specified by this parameter is the project root,
1111
#' and \code{FALSE} otherwise
1212
#' @param desc A textual description of the test criterion
13+
#' @param subdir Subdirectories to start the search in, if found
1314
#'
1415
#' @return
1516
#' An S3 object of class \code{root_criterion} wit the following members:
@@ -25,18 +26,30 @@
2526
#' \dontrun{
2627
#' is_r_package$make_fix_file(".")
2728
#' }
28-
root_criterion <- function(testfun, desc) {
29+
root_criterion <- function(testfun, desc, subdir = NULL) {
2930
if (!isTRUE(all.equal(names(formals(testfun)), "path"))) {
3031
stop("testfun must be a function with one argument 'path'")
3132
}
33+
34+
full_desc <- paste0(
35+
desc,
36+
if (!is.null(subdir)) paste0(
37+
" (also look in subdirectories: ",
38+
paste0("'", subdir, "'", collapse = ", "),
39+
")"
40+
)
41+
)
42+
3243
criterion <- structure(
3344
list(
3445
#' @return
3546
#' \describe{
3647
#' \item{\code{testfun}}{The \code{testfun} argument}
3748
testfun = testfun,
3849
#' \item{\code{desc}}{The \code{desc} argument}
39-
desc = desc
50+
desc = full_desc,
51+
#' \item{\code{subdir}}{The \code{subdir} argument}
52+
subdir = subdir
4053
),
4154
class = "root_criterion"
4255
)

R/file.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
#' @param criterion A criterion, will be coerced using
1212
#' \code{\link{as.root_criterion}}
1313
#' @param path The start directory
14-
#' @param ... Additional arguments passed to \code{\link{file.path}}
15-
#' @return The normalized path of the root as specified by the search criteria.
14+
#' @param ... Further path components passed to \code{\link{file.path}}
15+
#' @return The normalized path of the root as specified by the search criteria,
16+
#' with the additional path components appended.
1617
#' Throws an error if no root is found
1718
#'
1819
#' @examples

R/has-file.R

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,40 @@ has_file_pattern <- function(pattern, contents = NULL, n = -1L) {
6666
root_criterion(testfun, desc)
6767
}
6868

69+
#' @details
70+
#' The \code{has_dirname} function constructs a criterion that checks if the
71+
#' \code{\link[base]{dirname}} has a specific name.
72+
#'
73+
#' @rdname root_criterion
74+
#' @param dirname A directory name, without subdirectories
75+
#' @export
76+
has_dirname <- function(dirname, subdir = NULL) {
77+
force(dirname)
78+
79+
testfun <- eval(bquote(function(path) {
80+
dir.exists(file.path(dirname(path), .(dirname)))
81+
}))
82+
83+
desc <- paste0("Directory name is '", dirname, "'")
84+
85+
root_criterion(testfun, desc, subdir = subdir)
86+
}
87+
6988
#' @export
7089
is_rstudio_project <- has_file_pattern("[.]Rproj$", contents = "^Version: ", n = 1L)
7190

7291
#' @export
7392
is_r_package <- has_file("DESCRIPTION", contents = "^Package: ")
7493

94+
#' @export
95+
is_remake_project <- has_file("remake.yml")
96+
7597
#' @export
7698
from_wd <- root_criterion(function(path) TRUE, "From current working directory")
7799

100+
#' @export
101+
is_testthat <- has_dirname("testthat", c("tests/testthat", "testthat"))
102+
78103
#' Prespecified criteria
79104
#'
80105
#' This is a collection of commonly used root criteria.
@@ -84,6 +109,8 @@ criteria <- structure(
84109
list(
85110
is_rstudio_project = is_rstudio_project,
86111
is_r_package = is_r_package,
112+
is_remake_project = is_remake_project,
113+
is_testthat = is_testthat,
87114
from_wd = from_wd
88115
),
89116
class = "root_criteria")
@@ -108,6 +135,21 @@ str.root_criteria <- function(object, ...) {
108135
#' @export
109136
"is_r_package"
110137

138+
#' @details
139+
#' \code{is_remake_project} looks for a \code{remake.yml} file.
140+
#'
141+
#' @rdname criteria
142+
#' @export
143+
"is_remake_project"
144+
145+
#' @details
146+
#' \code{is_testthat} looks for the \code{testthat} directory, works when
147+
#' developing, testing, and checking a package.
148+
#'
149+
#' @rdname criteria
150+
#' @export
151+
"is_testthat"
152+
111153
#' @details
112154
#' \code{from_wd} uses the current working directory.
113155
#'
@@ -124,10 +166,7 @@ list_files <- function(path, filename) {
124166
}
125167

126168
is_dir <- function(x) {
127-
if (getRversion() >= "3.2")
128-
file.info(x, extra_cols = FALSE)$isdir
129-
else
130-
file.info(x)$isdir
169+
dir.exists(x)
131170
}
132171

133172
match_contents <- function(f, contents, n) {

R/root.R

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
find_root <- function(criterion, path = ".") {
2727
criterion <- as.root_criterion(criterion)
2828

29-
original_path <- path
30-
path <- normalizePath(path, winslash = "/", mustWork = TRUE)
29+
path <- start_path(path, criterion$subdir)
3130

3231
for (i in seq_len(.MAX_DEPTH)) {
3332
if (criterion$testfun(path)) {
@@ -47,6 +46,19 @@ find_root <- function(criterion, path = ".") {
4746

4847
.MAX_DEPTH <- 100L
4948

49+
start_path <- function(path, subdirs) {
50+
path <- normalizePath(path, winslash = "/", mustWork = TRUE)
51+
52+
for (subdir in subdirs) {
53+
subdir_path <- file.path(path, subdir)
54+
if (dir.exists(subdir_path)) {
55+
return(subdir_path)
56+
}
57+
}
58+
59+
path
60+
}
61+
5062
# Borrowed from devtools
5163
is_root <- function(path) {
5264
identical(normalizePath(path, winslash = "/"),

R/rprojroot-package.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
#'
66
#' @examples
77
#' criteria
8+
#' \dontrun{
89
#' is_r_package$find_file("NAMESPACE")
910
#' root_fun <- is_r_package$make_fix_file()
1011
#' root_fun("NAMESPACE")
12+
#' }
13+
#' @import backports
1114
"_PACKAGE"

R/shortcut.R

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,11 @@ find_rstudio_root_file <- is_rstudio_project$find_file
55
#' @rdname find_root_file
66
#' @export
77
find_package_root_file <- is_r_package$find_file
8+
9+
#' @rdname find_root_file
10+
#' @export
11+
find_remake_root_file <- is_remake_project$find_file
12+
13+
#' @rdname find_root_file
14+
#' @export
15+
find_testthat_root_file <- is_testthat$find_file

0 commit comments

Comments
 (0)