Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dir common remove #35

Merged
merged 3 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: reuseme
Title: Collections of Utility Functions to Work Across Projects
Version: 0.0.2.9002
Version: 0.0.2.9003
Authors@R:
person("Olivier", "Roy", , "olivierroy71@hotmail.com", role = c("aut", "cre"))
Description: Allows you to browse current projects, rename files safely,
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* In `proj_outline()`, `proj` has been renamed `path`, but still accepts a project name,
that will passed on to `proj_list()`

* Removed `dir_common` from `file_outline()` (#35)

## Fixes

* `file_outline()` now recognize `describe()` test calls.
Expand Down
3 changes: 2 additions & 1 deletion R/markup.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ link_local_gh_issue <- function(x, repo_home) {
x
)
}
find_pkg_org_repo <- function(dir_common = NULL, file = NULL) {
find_pkg_org_repo <- function(file = NULL) {
rlang::local_interactive(FALSE)
withr::local_options("usethis.quiet" = TRUE)
dir_common <- get_dir_common_outline(file)
if (!is.null(dir_common)) {
pkg_path <- tryCatch(
rprojroot::find_package_root_file(path = dir_common),
Expand Down
35 changes: 12 additions & 23 deletions R/outline.R
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
#' @param dir_tree If `TRUE`, will print the [fs::dir_tree()] or non-R files in
#' the directory
#' @param recent_only Show outline for recent files
#' @param dir_common (Do not use it)
#' @inheritParams fs::dir_ls
#' @returns A `outline_report` object that contains the information. Inherits
#' `tbl_df`.
Expand Down Expand Up @@ -84,8 +83,7 @@ file_outline <- function(path = active_rs_doc(),
pattern = NULL,
alpha = FALSE,
print_todo = TRUE,
recent_only = FALSE,
dir_common = NULL) {
recent_only = FALSE) {
# To contribute to this function, take a look at .github/CONTRIBUTING
check_string(pattern, allow_null = TRUE)

Expand Down Expand Up @@ -114,9 +112,6 @@ file_outline <- function(path = active_rs_doc(),
fs::path_real(path = path) # verify if the files exist
}

# if (rstudioapi::rstudio)
dir_common <- get_dir_common_outline(dir_common, path)

path <- stringr::str_sort(path)
file_content <- rlang::set_names(path)
# Not warn
Expand Down Expand Up @@ -169,7 +164,7 @@ file_outline <- function(path = active_rs_doc(),
}
# File outline ===================
# strip outline element .data$outline = `# Section 1` becomes `Section 1`
file_sections1 <- display_outline_element(file_sections0, dir_common)
file_sections1 <- display_outline_element(file_sections0)

if (is.null(pattern)) {
#file_sections1 <- file_sections1[!is.na(file_sections1$outline_el), ]
Expand All @@ -194,8 +189,7 @@ file_outline <- function(path = active_rs_doc(),
)
# Create hyperlink in console
file_sections <- construct_outline_link(
file_sections1,
dir_common
file_sections1
)

file_sections$recent_only <- recent_only
Expand Down Expand Up @@ -239,7 +233,7 @@ proj_outline <- function(path = active_rs_proj(), pattern = NULL, dir_tree = FAL
#' @export
dir_outline <- function(path = ".", pattern = NULL, dir_tree = FALSE, alpha = FALSE, recent_only = FALSE, recurse = FALSE) {
dir <- fs::path_real(path)
file_exts <- c("R", "qmd", "Rmd", "md", "Rmarkdown")
file_exts <- c("R", "RProfile", "qmd", "Rmd", "md", "Rmarkdown")
file_exts_regex <- paste0("*.", file_exts, "$", collapse = "|")

file_list_to_outline <- fs::dir_ls(
Expand Down Expand Up @@ -268,7 +262,7 @@ dir_outline <- function(path = ".", pattern = NULL, dir_tree = FALSE, alpha = FA
invert = TRUE
)
}
file_outline(path = file_list_to_outline, pattern = pattern, dir_common = dir, alpha = alpha, recent_only = recent_only)
file_outline(path = file_list_to_outline, pattern = pattern, alpha = alpha, recent_only = recent_only)
}

exclude_example_files <- function(path) {
Expand Down Expand Up @@ -499,9 +493,9 @@ scrub_duplicate_outline <- function(x) {
# Includes removing headings comments
# Remove title =
# Removing quotes, etc.
display_outline_element <- function(.data, dir_common) {
display_outline_element <- function(.data) {
x <- .data
org_repo <- find_pkg_org_repo(dir_common, unique(x$file))
org_repo <- find_pkg_org_repo(unique(x$file))
if (!is.null(org_repo)) {
x$outline_el <- link_local_gh_issue(x$content, org_repo)
} else {
Expand Down Expand Up @@ -599,7 +593,8 @@ define_important_element <- function(.data) {
)
}

construct_outline_link <- function(.data, dir_common) {
construct_outline_link <- function(.data) {
dir_common <- get_dir_common_outline(path = .data$file)
is_saved_doc <- !any(.data$file == "unsaved-doc.R")
is_active_doc <- length(unique(.data$file)) == 1L
rs_avail_file_link <- is_rstudio("2023.09.0.375") # better handling after
Expand Down Expand Up @@ -736,15 +731,9 @@ arrange_outline <- function(x) {
x[ordered_rows, ]
}

get_dir_common_outline <- function(dir_common, path) {
if (!is.null(dir_common)) {
dir_common <- tryCatch(
fs::path_real(dir_common),
error = function(e) {
cli::cli_abort("Don't specify `dir_common`, leave it as default", .internal = TRUE, parent = e)
}
)
} else if (rlang::has_length(path, 1)) {
get_dir_common_outline <- function(path) {
path <- unique(path)
if (rlang::has_length(path, 1)) {
# If a single path
root_path <- tryCatch(
rprojroot::find_root_file(
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ bench::mark(
#> # A tibble: 1 × 6
#> expression min median `itr/sec` mem_alloc `gc/sec`
#> <bch:expr> <bch:tm> <bch:tm> <dbl> <bch:byt> <dbl>
#> 1 outline <- proj_outline() 481ms 491ms 2.04 22.6MB 4.08
#> 1 outline <- proj_outline() 560ms 560ms 1.79 22.7MB 3.57
```

<details>
Expand Down
5 changes: 1 addition & 4 deletions man/outline.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.