Skip to content

Commit 54a8b09

Browse files
committed
Merge branch 'master' into f-abs
2 parents b5d6bf1 + 4999f9a commit 54a8b09

28 files changed

+127
-109
lines changed

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.3.2.9000
3+
Version: 1.3.2.9001
44
Authors@R:
55
person(given = "Kirill",
66
family = "M\u00fcller",
@@ -20,6 +20,7 @@ Imports:
2020
backports
2121
Suggests:
2222
knitr,
23+
lifecycle,
2324
mockr,
2425
rmarkdown,
2526
testthat,

NAMESPACE

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
# Generated by roxygen2: do not edit by hand
22

33
S3method("|",root_criterion)
4-
S3method(as.root_criterion,default)
54
S3method(as_root_criterion,character)
65
S3method(as_root_criterion,default)
76
S3method(as_root_criterion,root_criterion)
87
S3method(format,root_criterion)
98
S3method(print,root_criterion)
109
S3method(str,root_criteria)
11-
export(as.root_criterion)
1210
export(as_root_criterion)
1311
export(criteria)
1412
export(find_package_root_file)
@@ -19,11 +17,10 @@ export(find_rstudio_root_file)
1917
export(find_testthat_root_file)
2018
export(from_wd)
2119
export(get_root_desc)
20+
export(has_basename)
2221
export(has_dir)
23-
export(has_dirname)
2422
export(has_file)
2523
export(has_file_pattern)
26-
export(is.root_criterion)
2724
export(is_drake_project)
2825
export(is_git_root)
2926
export(is_projectile_project)

NEWS.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1+
# rprojroot 1.3.2.9001 (2020-11-09)
2+
3+
- `has_basename()` replaces `has_dirname()` to avoid confusion (#63).
4+
- The `is_dirname()` criterion no longer considers sibling directories (#44).
5+
- Move to GitHub Actions (#52).
6+
- Re-license as MIT (#50).
7+
8+
19
# rprojroot 1.3.2.9000 (2018-03-29)
210

311
- Rename `as.` and `is.` functions to `as_` and `is_`, deprecate old versions.
412
- New `is_drake_project` criterion (#34).
513
- Add `subdir` argument to `make_fix_file()` (#33, @BarkleyBG).
614
- Update documentation for version control criteria (#35, @uribo).
715
- Availability of suggested packages knitr and rmarkdown, and pandoc, is now checked before running the corresponding tests.
8-
- rprojroot has been re-licensed as MIT (#50).
916

1017

1118
# rprojroot 1.3-2 (2017-12-22)

R/criterion.R

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -124,27 +124,12 @@ is_root_criterion <- function(x) {
124124
inherits(x, "root_criterion")
125125
}
126126

127-
#' @rdname deprecated
128-
#' @inheritParams is_root_criterion
129-
#' @export
130-
is.root_criterion <- function(x) {
131-
.Deprecated("is_root_criterion")
132-
is_root_criterion(x)
133-
}
134-
135127
#' @rdname root_criterion
136128
#' @export
137129
as_root_criterion <- function(x) UseMethod("as_root_criterion", x)
138130

139-
#' @rdname deprecated
140-
#' @export
141-
as.root_criterion <- function(x) {
142-
.Deprecated("as_root_criterion")
143-
UseMethod("as.root_criterion", x)
144-
}
145-
146131
#' @details
147-
#' The `as.root_criterion()` function accepts objects of class
132+
#' The `as_root_criterion()` function accepts objects of class
148133
#' `root_criterion`, and character values; the latter will be
149134
#' converted to criteria using `has_file`.
150135
#'
@@ -163,11 +148,6 @@ as_root_criterion.default <- function(x) {
163148
stop("Cannot coerce ", x, " to type root_criterion.", call. = FALSE)
164149
}
165150

166-
#' @export
167-
as.root_criterion.default <- function(x) {
168-
as_root_criterion(x)
169-
}
170-
171151
#' @export
172152
format.root_criterion <- function(x, ...) {
173153
if (length(x$desc) > 1) {

R/deprecated.R

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

R/has-file.R

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ has_file <- function(filepath, contents = NULL, n = -1L) {
2222
if (!file.exists(testfile)) {
2323
return(FALSE)
2424
}
25-
if (is_dir(testfile)) {
25+
if (dir.exists(testfile)) {
2626
return(FALSE)
2727
}
2828
match_contents(testfile, .(contents), .(n))
@@ -52,10 +52,7 @@ has_dir <- function(filepath) {
5252

5353
testfun <- eval(bquote(function(path) {
5454
testfile <- file.path(path, .(filepath))
55-
if (!file.exists(testfile)) {
56-
return(FALSE)
57-
}
58-
is_dir(testfile)
55+
dir.exists(testfile)
5956
}))
6057

6158
desc <- paste0("contains a directory `", filepath, "`")
@@ -101,20 +98,22 @@ has_file_pattern <- function(pattern, contents = NULL, n = -1L) {
10198
}
10299

103100
#' @details
104-
#' The `has_dirname()` function constructs a criterion that checks if the
105-
#' [base::dirname()] has a specific name.
101+
#' The `has_basename()` function constructs a criterion that checks if the
102+
#' [base::basename()] of the root directory has a specific name,
103+
#' with support for case-insensitive file systems.
106104
#'
107105
#' @rdname root_criterion
108-
#' @param dirname A directory name, without subdirectories
106+
#' @param basename A directory name, without subdirectories
109107
#' @export
110-
has_dirname <- function(dirname, subdir = NULL) {
111-
force(dirname)
108+
has_basename <- function(basename, subdir = NULL) {
109+
force(basename)
112110

113111
testfun <- eval(bquote(function(path) {
114-
dir.exists(file.path(dirname(path), .(dirname)))
112+
# Support case insensitive file systems.
113+
tolower(basename(path)) == tolower(.(basename)) && dir.exists(file.path(dirname(path), .(basename)))
115114
}))
116115

117-
desc <- paste0("directory name is `", dirname, "`")
116+
desc <- paste0("directory name is `", basename, "`")
118117

119118
root_criterion(testfun, desc, subdir = subdir)
120119
}
@@ -144,7 +143,7 @@ is_svn_root <- has_dir(".svn")
144143
is_vcs_root <- is_git_root | is_svn_root
145144

146145
#' @export
147-
is_testthat <- has_dirname("testthat", c("tests/testthat", "testthat"))
146+
is_testthat <- has_basename("testthat", c("tests/testthat", "testthat"))
148147

149148
#' @export
150149
from_wd <- root_criterion(function(path) TRUE, "from current working directory")
@@ -262,15 +261,11 @@ str.root_criteria <- function(object, ...) {
262261

263262
list_files <- function(path, filename) {
264263
files <- dir(path = path, pattern = filename, all.files = TRUE, full.names = TRUE)
265-
dirs <- is_dir(files)
264+
dirs <- dir.exists(files)
266265
files <- files[!dirs]
267266
files
268267
}
269268

270-
is_dir <- function(x) {
271-
dir.exists(x)
272-
}
273-
274269
match_contents <- function(f, contents, n) {
275270
if (is.null(contents)) {
276271
return(TRUE)

R/rprojroot-package.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#' @details
22
#' See the "Value" section in [root_criterion()] for documentation
3-
#' of root criterion objects, and [criteria()] for useful predefined
3+
#' of root criterion objects, and [criteria] for useful predefined
44
#' root criteria.
55
#'
66
#' @examples
@@ -11,5 +11,4 @@
1111
#' root_fun("NAMESPACE")
1212
#' }
1313
#' @import backports
14-
#' @api
1514
"_PACKAGE"

R/thisfile.R

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
#' @title Determines the path of the currently running script
2-
#' @description \R does not store nor export the path of the currently running
1+
#' Determines the path of the currently running script
2+
#'
3+
#' @description
4+
#' `r lifecycle::badge("soft-deprecated")`
5+
#'
6+
#' \R does not store nor export the path of the currently running
37
#' script. This is an attempt to circumvent this limitation by applying
48
#' heuristics (such as call stack and argument inspection) that work in many
59
#' cases.
@@ -12,17 +16,29 @@
1216
#' or run with `Rscript` or using the `--file` parameter to the
1317
#' `R` executable. For code run with `Rscript`, the exact value
1418
#' of the parameter passed to `Rscript` is returned.
19+
#'
20+
#' @section Life cycle:
21+
#'
22+
#' These functions are now available in the \pkg{whereami} package.
23+
#'
1524
#' @return The path of the currently running script, NULL if it cannot be
1625
#' determined.
1726
#' @seealso [base::source()], [utils::Rscript()], [base::getwd()]
1827
#' @references [https://stackoverflow.com/q/1815606/946850]()
1928
#' @author Kirill Müller, Hadley Wickham, Michael R. Head
29+
#' @keywords internal
2030
#' @examples
2131
#' \dontrun{
2232
#' thisfile()
2333
#' }
2434
#' @export
2535
thisfile <- function() {
36+
lifecycle::deprecate_soft(
37+
"2.0.0",
38+
"rprojroot::thisfile()",
39+
"whereami::thisfile()"
40+
)
41+
2642
if (!is.null(res <- thisfile_source())) {
2743
res
2844
} else if (!is.null(res <- thisfile_r())) {
@@ -39,6 +55,12 @@ thisfile <- function() {
3955
#' @rdname thisfile
4056
#' @export
4157
thisfile_source <- function() {
58+
lifecycle::deprecate_soft(
59+
"2.0.0",
60+
"rprojroot::thisfile_source()",
61+
"whereami::thisfile_source()"
62+
)
63+
4264
for (i in -(1:sys.nframe())) {
4365
if (identical(args(sys.function(i)), args(base::source))) {
4466
return(normalizePath(sys.frame(i)$ofile))
@@ -52,6 +74,12 @@ thisfile_source <- function() {
5274
#' @importFrom utils tail
5375
#' @export
5476
thisfile_r <- function() {
77+
lifecycle::deprecate_soft(
78+
"2.0.0",
79+
"rprojroot::thisfile_r()",
80+
"whereami::thisfile_r()"
81+
)
82+
5583
cmd_args <- commandArgs(trailingOnly = FALSE)
5684
if (!grepl("^R(?:|term)(?:|[.]exe)$", basename(cmd_args[[1L]]), ignore.case = TRUE)) {
5785
return(NULL)
@@ -77,6 +105,12 @@ thisfile_r <- function() {
77105
#' @importFrom utils tail
78106
#' @export
79107
thisfile_rscript <- function() {
108+
lifecycle::deprecate_soft(
109+
"2.0.0",
110+
"rprojroot::thisfile_rscript()",
111+
"whereami::thisfile_rscript()"
112+
)
113+
80114
cmd_args <- commandArgs(trailingOnly = FALSE)
81115
if (!grepl("^R(?:term|script)(?:|[.]exe)$", basename(cmd_args[[1L]]), ignore.case = TRUE)) {
82116
return(NULL)
@@ -100,6 +134,12 @@ thisfile_rscript <- function() {
100134
#' @rdname thisfile
101135
#' @export
102136
thisfile_knit <- function() {
137+
lifecycle::deprecate_soft(
138+
"2.0.0",
139+
"rprojroot::thisfile_knit()",
140+
"whereami::thisfile_knit()"
141+
)
142+
103143
if (requireNamespace("knitr")) {
104144
return(knitr::current_input(dir = TRUE))
105145
}

README.Rmd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ rlang::local_interactive(FALSE)
1717
# [rprojroot](https://r-lib.github.io/rprojroot)
1818

1919
<!-- badges: start -->
20+
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable)
2021
[![rcc](https://github.com/r-lib/rprojroot/workflows/rcc/badge.svg)](https://github.com/r-lib/rprojroot/actions)
2122
[![codecov.io](https://codecov.io/github/r-lib/rprojroot/coverage.svg?branch=master)](https://codecov.io/github/r-lib/rprojroot?branch=master)
2223
[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/rprojroot)](https://cran.r-project.org/package=rprojroot)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
<!-- badges: start -->
66

7+
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://www.tidyverse.org/lifecycle/#stable)
78
[![rcc](https://github.com/r-lib/rprojroot/workflows/rcc/badge.svg)](https://github.com/r-lib/rprojroot/actions) [![codecov.io](https://codecov.io/github/r-lib/rprojroot/coverage.svg?branch=master)](https://codecov.io/github/r-lib/rprojroot?branch=master) [![CRAN\_Status\_Badge](https://www.r-pkg.org/badges/version/rprojroot)](https://cran.r-project.org/package=rprojroot)
89

910
<!-- badges: end -->

0 commit comments

Comments
 (0)