Skip to content

Commit

Permalink
Don't use rprojroot after all
Browse files Browse the repository at this point in the history
Just implement a depth restriction, so hopefully we don't recurse into
directories with thousands of files.
  • Loading branch information
jimhester committed Oct 11, 2022
1 parent 4b051fc commit 3009505
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Imports:
jsonlite,
knitr,
rex,
rprojroot,
stats,
utils,
xml2 (>= 1.0.0),
Expand Down
37 changes: 26 additions & 11 deletions R/lint.R
Original file line number Diff line number Diff line change
Expand Up @@ -370,30 +370,45 @@ reorder_lints <- function(lints) {
)]
}


has_description <- function(path) {
desc_info <- file.info(file.path(path, "DESCRIPTION"))
!is.na(desc_info$size) && desc_info$size > 0.0 && !desc_info$isdir
}

find_package <- function(path) {
if (!dir.exists(path)) {
depth <- 2
while(!has_description(path)) {
path <- dirname(path)
if (is_root(path) || depth <= 0) {
return(NULL)
}
depth <- depth - 1
}
tryCatch(
rprojroot::find_root(path = path, criterion = rprojroot::is_r_package),
error = function(e) NULL
)
path
}

find_rproj_or_package <- function(path) {
if (!dir.exists(path)) {
path <- normalizePath(path, mustWork = FALSE)

depth <- 2
while(!(has_description(path) || has_rproj(path))) {
path <- dirname(path)
if (is_root(path) || depth <= 0) {
return(NULL)
}
depth <- depth - 1
}
tryCatch(
rprojroot::find_root(path = path, criterion = rprojroot::is_rstudio_project | rprojroot::is_r_package),
error = function(e) NULL
)
path
}

has_rproj <- function(path) {
length(head(Sys.glob(file.path(path, "*.Rproj")), n = 1L)) == 1
}

find_rproj_at <- function(path) {
head(Sys.glob(file.path(path, "*.Rproj")), n = 1L)
}

is_root <- function(path) {
identical(path, dirname(path))
}
Expand Down

0 comments on commit 3009505

Please sign in to comment.