diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 0f2fe08..d46a617 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -6,7 +6,7 @@ on: pull_request: branches: [main, master] -name: R-CMD-check +name: R-CMD-check.yaml permissions: read-all diff --git a/.github/workflows/pkgdown.yaml b/.github/workflows/pkgdown.yaml index c9f0165..4bbce75 100644 --- a/.github/workflows/pkgdown.yaml +++ b/.github/workflows/pkgdown.yaml @@ -9,7 +9,7 @@ on: types: [published] workflow_dispatch: -name: pkgdown +name: pkgdown.yaml permissions: read-all diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index fefc52e..9882260 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -6,7 +6,7 @@ on: pull_request: branches: [main, master] -name: test-coverage +name: test-coverage.yaml permissions: read-all diff --git a/DESCRIPTION b/DESCRIPTION index 193e55a..256121a 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: reuseme Title: Collections of Utility Functions to Work Across Projects -Version: 0.0.2.9005 +Version: 0.0.2.9006 Authors@R: person("Olivier", "Roy", , "olivierroy71@hotmail.com", role = c("aut", "cre")) Description: Allows you to browse current projects, rename files safely, @@ -45,4 +45,4 @@ Suggests: Config/testthat/edition: 3 Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 diff --git a/NEWS.md b/NEWS.md index e7c9c5c..e72c348 100644 --- a/NEWS.md +++ b/NEWS.md @@ -17,6 +17,9 @@ that will passed on to `proj_list()` * `file_outline()` result is now a simpler data frame. The cli links are now created in the print method. (which makes more sense for truncation) +* `use_todo("global::todo")` no longer works out of the box. You need to set `options(reuseme.global_todo = fs::path("Documents"))` explicitly (in .Rprofile) for example to make sure + reuseme can write in a directory. + ## Fixes * `rename_files2()` now looks in `.Rbuildignore` to see if some files should be replaced. @@ -51,6 +54,8 @@ that will passed on to `proj_list()` * Package versions in NEWS.md are now normalized to yield better results. +* `active_rs_doc()` returns the relative path if in RStudio project. + # reuseme 0.0.2 * `complete_todo()` no longer deletes the full line. It only deletes what it says it deletes (#27). diff --git a/R/open.R b/R/open.R index b1a6144..a1514c9 100644 --- a/R/open.R +++ b/R/open.R @@ -57,6 +57,14 @@ active_rs_doc <- function() { cli::cli_abort("Either RStudio is not available or you are trying to map an unsaved file") }) path <- fs::path_expand_r(path) + active_proj <- proj_get2() + if (is.null(active_proj)) { + return(invisible(path)) + } + if (isTRUE(fs::path_has_parent(path, active_proj))) { + path <- fs::path_rel(path) + } + path # likely not hapenning on RStudio >= 2023.06.2 } diff --git a/R/outdated-pkgs.R b/R/outdated-pkgs.R index 80b75ed..4c1dce6 100644 --- a/R/outdated-pkgs.R +++ b/R/outdated-pkgs.R @@ -22,12 +22,17 @@ outdated_pkgs <- function(type = c("binary", "source")) { default_repo <- getOption("repos")[[1]] default_repo <- sub("/$", "", default_repo) default_repo <- sub("https://", "", default_repo, fixed = TRUE) + if (!grepl("packagemanager", default_repo)) { + # ppm is not well detected + access_repo <- tryCatch(curl::nslookup(default_repo), + error = function(e) { + FALSE + } + ) + } else { + access_repo <- TRUE + } - access_repo <- tryCatch(curl::nslookup(default_repo), - error = function(e) { - FALSE - } - ) } else { access_repo <- TRUE } @@ -46,7 +51,12 @@ outdated_pkgs <- function(type = c("binary", "source")) { outdated_pkg_mat <- utils::old.packages(type = type, lib.loc = .libPaths()[1]) if (rlang::has_length(outdated_pkg_mat) && !is.null(getOption("reuseme.ignore_update"))) { - indices_to_discard <- which(rownames(outdated_pkg_mat) %in% getOption("reuseme.ignore_update")) + if (type == "source") { + # only disallow update when building from source. + indices_to_discard <- which(rownames(outdated_pkg_mat) %in% getOption("reuseme.ignore_update")) + } else { + indices_to_discard <- integer(0L) + } if (rlang::has_length(indices_to_discard)) { # because matrix[-character(0), ] destroys |> the matrix? outdated_pkg_mat <- outdated_pkg_mat[-indices_to_discard, , drop = FALSE] } diff --git a/R/outline-criteria.R b/R/outline-criteria.R index b4e34b3..2157944 100644 --- a/R/outline-criteria.R +++ b/R/outline-criteria.R @@ -264,7 +264,7 @@ define_outline_criteria <- function(.data, exclude_todos) { is_object_title = FALSE, tag = NA_character_, topic = NA_character_, - is_cross_ref = stringr::str_detect(content, "docs_links?\\(.") & !stringr::str_detect(content, "@param|\\{\\."), + is_cross_ref = stringr::str_detect(content, "docs_(links|add.+)?\\(.") & !stringr::str_detect(content, "@param|\\{\\."), is_function_def = grepl("<- function(", content, fixed = TRUE) & !stringr::str_starts(content, "\\s*#"), is_tab_or_plot_title = o_is_tab_plot_title(content) & !is_section_title & !is_function_def, ) diff --git a/R/outline.R b/R/outline.R index ba5c9e4..9e9b18d 100644 --- a/R/outline.R +++ b/R/outline.R @@ -744,14 +744,14 @@ display_outline_element <- function(.data) { y <- dplyr::mutate( x, has_title_el = - ((line == 1 & !is_todo_fixme & !is_test_name & !is_snap_file) | + ((line == 1 & !is_todo_fixme & !is_test_name & !is_snap_file & !is_cross_ref) | (is_doc_title & !is_subtitle & !is_snap_file & !is_second_level_heading_or_more)) & !is_news, .by = "file" ) y <- withCallingHandlers( dplyr::mutate(y, title_el_line = ifelse(has_title_el, line[ - (line == 1 & !is_todo_fixme & !is_test_name & !is_snap_file) | + (line == 1 & !is_todo_fixme & !is_test_name & !is_snap_file & !is_cross_ref) | (is_doc_title & !is_subtitle & !is_snap_file & !is_second_level_heading_or_more) ][1], # take the first element to avoid problems (may be the reason why problems occur) NA_integer_ diff --git a/R/rename.R b/R/rename.R index baffe7d..6cffda7 100644 --- a/R/rename.R +++ b/R/rename.R @@ -90,7 +90,7 @@ rename_files2 <- function(old, # Warn if some related files are found. If I have file.R and file.csv, # this will warn if I rename file.R, but not file.csv related_files <- fs::dir_ls(regexp = paste0(basename_remove_ext(old), "\\."), recurse = TRUE) - related_files <- fs::path_filter(related_files, "_snaps/|_book/|_files|_freeze|renv/", invert = TRUE) + related_files <- fs::path_filter(related_files, "_snaps/|_book/|_files|_freeze|renv/|\\~\\$", invert = TRUE) related_files <- setdiff(related_files, old) # remove project name from conflicts. diff --git a/R/todo.R b/R/todo.R index 5d3cd99..2e8fef9 100644 --- a/R/todo.R +++ b/R/todo.R @@ -7,7 +7,11 @@ #' use `usethis::use_git_ignore("TODO.R")` if you don't want your `TODO.R` file #' #' to be included in git. If using in a package directory, use -#' `usethis::use_build_ignore("TODO.R")` to prevent a note in `R CMD CHECK` +#' `usethis::use_build_ignore("TODO.R")` to prevent a note in `R CMD CHECK`. +#' +#' If you want to write to a global TODO, use +#' +#' `options(reuseme.global_todo = fs::path("Documents"))` to write there. #' #' @param todo A character vector of lines to add to the TODO file. See details #' for special handling. @@ -219,7 +223,13 @@ compute_path_todo <- function(todo, proj) { # Handle special global and all syntax for todo items. if (proj %in% c("global", "all")) { - proj_path <- Sys.getenv("R_USER", Sys.getenv("HOME")) # ?base::path.expand + proj_path <- getOption("reuseme.global_todo") + if (is.null(proj_path)) { + cli::cli_abort(c( + "You must set a global option reuseme.global_todo to write to a global todo.", + i ="A good option for cross-platform is `options(reuseme.global_todo = fs::path_home(\"Documents\"))" + )) + } } else if (!is_active_proj) { # in interactive session with options set proj_path <- proj_list(proj) diff --git a/README.Rmd b/README.Rmd index 23639ee..86dd54f 100644 --- a/README.Rmd +++ b/README.Rmd @@ -20,8 +20,7 @@ knitr::opts_chunk$set( [![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) [![CRAN status](https://www.r-pkg.org/badges/version/reuseme)](https://CRAN.R-project.org/package=reuseme) [![R-CMD-check](https://github.com/olivroy/reuseme/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/olivroy/reuseme/actions/workflows/R-CMD-check.yaml) -[![Codecov test coverage](https://codecov.io/gh/olivroy/reuseme/branch/main/graph/badge.svg)](https://app.codecov.io/gh/olivroy/reuseme?branch=main) - +[![Codecov test coverage](https://codecov.io/gh/olivroy/reuseme/graph/badge.svg)](https://app.codecov.io/gh/olivroy/reuseme) The goal of reuseme is to provide utility functions for project management across RStudio projects. diff --git a/README.md b/README.md index 49070f2..cd975b7 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,7 @@ experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](h status](https://www.r-pkg.org/badges/version/reuseme)](https://CRAN.R-project.org/package=reuseme) [![R-CMD-check](https://github.com/olivroy/reuseme/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/olivroy/reuseme/actions/workflows/R-CMD-check.yaml) [![Codecov test -coverage](https://codecov.io/gh/olivroy/reuseme/branch/main/graph/badge.svg)](https://app.codecov.io/gh/olivroy/reuseme?branch=main) - +coverage](https://codecov.io/gh/olivroy/reuseme/graph/badge.svg)](https://app.codecov.io/gh/olivroy/reuseme) The goal of reuseme is to provide utility functions for project @@ -210,6 +209,7 @@ outline #> #> ── `R/files-conflicts.R` #> `i` TODO insert in either proj_outline, or rename_file +#> `i` FIXME in Rbuilignore, change `^_pkgdown\.yml$` to `_pkgdown.yml` to make sure it works #> `i` TODO probably needs a `detect_genuine_path()` #> `i` Helpers #> `i` TODO Add false positive references @@ -254,6 +254,7 @@ outline #> `i` Print interactive outline of file sections [outline] #> `i` `file_outline()` #> `i` File outline +#> `i` TODO expand this to apply to most generated files #> `i` Print method #> `i` TODO since April 2024, cli links work almost out of the box in VScode? microsoft/vscode#176812 () #> `i` Step: tweak outline look as they show @@ -550,6 +551,38 @@ outline #> ── `tests/testthat/test-todo.R` #> `i` Marking TODO as done detects tags #> +#> ── `TODO.R` +#> `i` TODO screenshot make the behaviour different when vignettes vs articles: vignettes should place it in man/figures, while articles could put it in vignettes/articles file. +#> `i` TODO screenshot RStudio addin to insert the code directly in the qmd doc. No longer needed with RStudio 2023.12 +#> `i` TODO use_family() to edit .R file to add @family data frames tags to roxygen +#> `i` TODO mutate_identity redundant if the focus pillar PR was merged. r-lib/pillar#585 () +#> `i` TODO rename if many matches, separate those with the exact path. +#> `i` TODO outline make ggtitle work +#> `i` TODO outline show extra msg only for some, but in file outline, not in proj? +#> `i` TODO outline detect help calls and apply markup. `?fs::file_show` disregard finishing `.` (not followed by dot) +#> `i` TODO outline renable cli info. +#> `i` TODO escape_markup doesn't work with complex operation {x^2} for example. Maybe if detecting something complex, use cli_escape function. escape-complex-markyp branch created to try to address this. +#> `i` TODO outline avoid evaluating in current env. +#> `i` TODO wrap regexps in functions +#> `i` TODO outline remove examples from outline. Sometimes commented code is caught. +#> `i` TODO outline roxygen comments processing should be left to `roxygen2::parse_file()` +#> `i` TODO outline show key like `pak::pkg_deps_tree()` does. +#> `i` TODO outline roxygen function title +#> `i` TODO outline remove ggtext markup from plot title. +#> `i` FIXME outline comments are now interpreted as section +#> `i` TODO outline todos in qmd file inside html comment +#> `i` TODO reframe more than one issue. nw drive +#> `i` TODO delete generated files +#> `i` TODO [check_referenced_files] doesn't check for 'R/file.R' +#> `i` TODO browse_pkg should open by default if no vignettes are found, because there is not much to do in the R-session. +#> `i` TODO exclude _files from `proj_list()` +#> `i` TODO rename_files should be less noisy about project name file +#> `i` TODO add_to_tricks(). when detecting TRICK like complete todo, but not remove line. requires a scheme. moves the item to tricks.md at the correct place. (copy to clipboard is probably enough) +#> `i` TODO use vapply() instead of purrr::map +#> `i` TODO rename_files() should know about .covrignore too +#> `i` TODO withr::local_dir for proj_outline. +#> `i` TODO add warn_conflicts = 'none' +#> #> ── `NEWS.md` #> `i` reuseme (development version) #> diff --git a/TODO.R b/TODO.R index 8758da2..3ae6bb0 100644 --- a/TODO.R +++ b/TODO.R @@ -30,3 +30,7 @@ # TODO [outline] family should be displayed differently.. # TODO [outline] find a way to make print bookmarks.. # TODO [outline] escape some content in headings see {.file tests/testthat/_outline/quarto-caps.md} for examples. +# TODO use vapply() instead of purrr::map +# TODO rename_files() should know about .covrignore too +# TODO withr::local_dir for proj_outline. +# TODO add warn_conflicts = 'none' diff --git a/man/filter_detect.Rd b/man/filter_detect.Rd index 4cb19d8..1d0542e 100644 --- a/man/filter_detect.Rd +++ b/man/filter_detect.Rd @@ -33,6 +33,10 @@ A data frame with relocated columns at first Shortcut for \code{\link[dplyr:filter]{dplyr::filter()}} and \code{\link[stringr:str_detect]{stringr::str_detect()}} } \examples{ +# don't specify column dplyr::band_members |> filter_detect("Beatles") +# specify columns +dplyr::band_members |> + filter_detect("Beatles", band) } diff --git a/man/use_todo.Rd b/man/use_todo.Rd index 9da58c0..d9a7903 100644 --- a/man/use_todo.Rd +++ b/man/use_todo.Rd @@ -29,7 +29,11 @@ If you use \code{use_todo()} with a version-control repository, you may want to use \code{usethis::use_git_ignore("TODO.R")} if you don't want your \code{TODO.R} file to be included in git. If using in a package directory, use -\code{usethis::use_build_ignore("TODO.R")} to prevent a note in \verb{R CMD CHECK} +\code{usethis::use_build_ignore("TODO.R")} to prevent a note in \verb{R CMD CHECK}. + +If you want to write to a global TODO, use + +\code{options(reuseme.global_todo = fs::path("Documents"))} to write there. } \examples{ if (FALSE) {