@@ -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
7089is_rstudio_project <- has_file_pattern(" [.]Rproj$" , contents = " ^Version: " , n = 1L )
7190
7291# ' @export
7392is_r_package <- has_file(" DESCRIPTION" , contents = " ^Package: " )
7493
94+ # ' @export
95+ is_remake_project <- has_file(" remake.yml" )
96+
7597# ' @export
7698from_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
126168is_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
133172match_contents <- function (f , contents , n ) {
0 commit comments