@@ -370,30 +370,45 @@ reorder_lints <- function(lints) {
370
370
)]
371
371
}
372
372
373
+
374
+ has_description <- function (path ) {
375
+ desc_info <- file.info(file.path(path , " DESCRIPTION" ))
376
+ ! is.na(desc_info $ size ) && desc_info $ size > 0.0 && ! desc_info $ isdir
377
+ }
378
+
373
379
find_package <- function (path ) {
374
- if (! dir.exists(path )) {
380
+ depth <- 2
381
+ while (! has_description(path )) {
375
382
path <- dirname(path )
383
+ if (is_root(path ) || depth < = 0 ) {
384
+ return (NULL )
385
+ }
386
+ depth <- depth - 1
376
387
}
377
- tryCatch(
378
- rprojroot :: find_root(path = path , criterion = rprojroot :: is_r_package ),
379
- error = function (e ) NULL
380
- )
388
+ path
381
389
}
382
390
383
391
find_rproj_or_package <- function (path ) {
384
- if (! dir.exists(path )) {
392
+ path <- normalizePath(path , mustWork = FALSE )
393
+
394
+ depth <- 2
395
+ while (! (has_description(path ) || has_rproj(path ))) {
385
396
path <- dirname(path )
397
+ if (is_root(path ) || depth < = 0 ) {
398
+ return (NULL )
399
+ }
400
+ depth <- depth - 1
386
401
}
387
- tryCatch(
388
- rprojroot :: find_root(path = path , criterion = rprojroot :: is_rstudio_project | rprojroot :: is_r_package ),
389
- error = function (e ) NULL
390
- )
402
+ path
403
+ }
404
+
405
+ has_rproj <- function (path ) {
406
+ length(head(Sys.glob(file.path(path , " *.Rproj" )), n = 1L )) == 1
391
407
}
392
408
393
409
find_rproj_at <- function (path ) {
394
410
head(Sys.glob(file.path(path , " *.Rproj" )), n = 1L )
395
411
}
396
-
397
412
is_root <- function (path ) {
398
413
identical(path , dirname(path ))
399
414
}
0 commit comments