Skip to content

Commit 3009505

Browse files
committed
Don't use rprojroot after all
Just implement a depth restriction, so hopefully we don't recurse into directories with thousands of files.
1 parent 4b051fc commit 3009505

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

DESCRIPTION

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ Imports:
3232
jsonlite,
3333
knitr,
3434
rex,
35-
rprojroot,
3635
stats,
3736
utils,
3837
xml2 (>= 1.0.0),

R/lint.R

+26-11
Original file line numberDiff line numberDiff line change
@@ -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+
373379
find_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

383391
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))) {
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

393409
find_rproj_at <- function(path) {
394410
head(Sys.glob(file.path(path, "*.Rproj")), n = 1L)
395411
}
396-
397412
is_root <- function(path) {
398413
identical(path, dirname(path))
399414
}

0 commit comments

Comments
 (0)