diff --git a/DESCRIPTION b/DESCRIPTION index 77ce1b3..0c27c71 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package -Package: rprofile +Package: rprofile.setup Title: My Rprofile in a Handy R Package -Version: 0.1.14 +Version: 0.2.0 Authors@R: person(given = "Colin", family = "Gillespie", diff --git a/NEWS.md b/NEWS.md index 3ddf8f1..f0219ea 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,10 +1,15 @@ +# rprofile.setup 0.2.0 _2023-07-19_ + * feat: Rename package as there is now an {rprofile} package on CRAN + * refactor: `get_r_sessions()` remove `greps` using `str_detect()` + * refactor: `stripspace()` only update if the file has changed + # rprofile 0.1.14 _2023-07-19_ * refactor: Remove importFrom where possible * feat: Use tibbles for lsos # rprofile 0.1.13 _2023-06-05_ - * fix: Use prompts from {prompt} to avoid odd terminal resizing. - + * fix: Use prompts from {prompt} to avoid odd terminal resizing. + # rprofile 0.1.12 _2022-11-08_ * Add `stripspace()` function for cleaning files * Remove `check.bounds` option - too noisy diff --git a/R/set-startup-info.R b/R/set-startup-info.R index 9bf83f2..96f4dba 100644 --- a/R/set-startup-info.R +++ b/R/set-startup-info.R @@ -123,12 +123,16 @@ get_internet = function() { return(con_str) } +remove_greps = function(r_sessions) { + stringr::str_detect() +} + get_r_sessions = function() { if (Sys.info()[["sysname"]] %in% c("Linux", "Darwin")) { - r_sessions = system2("ps", args = c("aux", "|", "grep", "rsession"), stdout = TRUE) - no_sessions = length(r_sessions) - 2 - r_sessions = system2("ps", args = c("aux", "|", "grep", "exec/R"), stdout = TRUE) - return(no_sessions + length(r_sessions) - 2) + r_sessions = c(system2("ps", args = c("aux", "|", "grep", "rsession"), stdout = TRUE), + system2("ps", args = c("aux", "|", "grep", "exec/R"), stdout = TRUE)) + no_of_sessions = sum(stringr::str_detect(r_sessions, "grep", negate = TRUE)) + return(no_of_sessions) } return("Unknown system") } diff --git a/R/stripspace.R b/R/stripspace.R index 9cc4f6f..1f016b8 100644 --- a/R/stripspace.R +++ b/R/stripspace.R @@ -4,9 +4,13 @@ stripspace = function() { fnames = list.files(pattern = "\\.R$|\\.qmd$|\\.Rmd$|\\.md$", full.names = TRUE, recursive = TRUE) tmp = tempfile() for (fname in fnames) { - cli::cli_alert("Updating {fname}") + hash1 = rlang::hash_file(fname) system2("git", c("stripspace", "<", fname, ">", tmp)) - system2("cat", c(tmp, ">", fname)) + hash2 = rlang::hash_file(tmp) + if (hash1 != hash2) { + cli::cli_alert("Updating {fname}") + system2("cat", c(tmp, ">", fname)) + } } return(invisible(NULL)) }