@@ -370,30 +370,45 @@ reorder_lints <- function(lints) {
370370 )]
371371}
372372
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+
373379find_package <- function (path ) {
374- if (! dir.exists(path )) {
380+ depth <- 2
381+ while (! has_description(path )) {
375382 path <- dirname(path )
383+ if (is_root(path ) || depth < = 0 ) {
384+ return (NULL )
385+ }
386+ depth <- depth - 1
376387 }
377- tryCatch(
378- rprojroot :: find_root(path = path , criterion = rprojroot :: is_r_package ),
379- error = function (e ) NULL
380- )
388+ path
381389}
382390
383391find_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 ))) {
385396 path <- dirname(path )
397+ if (is_root(path ) || depth < = 0 ) {
398+ return (NULL )
399+ }
400+ depth <- depth - 1
386401 }
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
391407}
392408
393409find_rproj_at <- function (path ) {
394410 head(Sys.glob(file.path(path , " *.Rproj" )), n = 1L )
395411}
396-
397412is_root <- function (path ) {
398413 identical(path , dirname(path ))
399414}
0 commit comments