Skip to content

Commit

Permalink
Merge branch 'r-1.0-7' into production
Browse files Browse the repository at this point in the history
  • Loading branch information
krlmlr committed Oct 23, 2016
2 parents e1b22aa + 7f358fc commit c1123d6
Show file tree
Hide file tree
Showing 25 changed files with 238 additions and 21 deletions.
15 changes: 11 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -37,7 +40,6 @@ matrix:
#r_packages
r_packages:
- covr
- roxygen2

#notifications
notifications:
Expand All @@ -48,13 +50,18 @@ 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:

#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)

# services

#before_install

# before_script
4 changes: 3 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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,
Expand Down
6 changes: 6 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,20 @@ 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)
export(find_testthat_root_file)
export(from_wd)
export(has_dirname)
export(has_file)
export(has_file_pattern)
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)
9 changes: 9 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
## 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.


## rprojroot 1.0-5 (2016-10-22)

- Use Travis instead of wercker.
Expand Down
17 changes: 15 additions & 2 deletions R/criterion.R
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -25,18 +26,30 @@
#' \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'")
}

full_desc <- paste0(
desc,
if (!is.null(subdir)) paste0(
" (also look in subdirectories: ",
paste0("'", subdir, "'", collapse = ", "),
")"
)
)

criterion <- structure(
list(
#' @return
#' \describe{
#' \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
),
class = "root_criterion"
)
Expand Down
5 changes: 3 additions & 2 deletions R/file.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
47 changes: 43 additions & 4 deletions R/has-file.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,40 @@ 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(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)

#' @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")

#' @export
is_testthat <- has_dirname("testthat", c("tests/testthat", "testthat"))

#' Prespecified criteria
#'
#' This is a collection of commonly used root criteria.
Expand All @@ -84,6 +109,8 @@ criteria <- structure(
list(
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")
Expand All @@ -108,6 +135,21 @@ 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{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.
#'
Expand All @@ -124,10 +166,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) {
Expand Down
16 changes: 14 additions & 2 deletions R/root.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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 = "/"),
Expand Down
3 changes: 3 additions & 0 deletions R/rprojroot-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +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"
8 changes: 8 additions & 0 deletions R/shortcut.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@ 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

#' @rdname find_root_file
#' @export
find_testthat_root_file <- is_testthat$find_file
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
9 changes: 9 additions & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -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
13 changes: 12 additions & 1 deletion man/criteria.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions man/find_root_file.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c1123d6

Please sign in to comment.