[mirror] Opinionated R package quickstart
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Generated docs for internal funcs

VisruthSK 34046e74 509b9f55

+48 -1
+48 -1
R/utils.R
··· 1 + #' Write Text to a Path 2 + #' 3 + #' Creates parent directories as needed, then writes `text` to `filepath`. 4 + #' 5 + #' @param text Character vector to write. 6 + #' @param filepath Destination file path. 7 + #' 8 + #' @return Invisibly returns `NULL`. 9 + #' @keywords internal 10 + #' @noRd 1 11 write_to_path <- function(text, filepath) { 2 - fs::dir_create(fs::path_dir(filepath), recurse = TRUE) 12 + fs::dir_create(fs::path_dir(filepath)) 3 13 writeLines(text, filepath) 4 14 } 5 15 16 + #' Find and Replace in a File 17 + #' 18 + #' Replaces matching text in a single file. 19 + #' 20 + #' @param from Pattern to replace. 21 + #' @param to Replacement text. 22 + #' @param file File path to modify. 23 + #' @param fixed Logical; if `TRUE`, use fixed matching. If `FALSE`, treat 24 + #' `from` as a regular expression. 25 + #' 26 + #' @return Invisibly returns `TRUE` if any replacement was made, otherwise 27 + #' invisibly returns `FALSE`. 28 + #' @keywords internal 29 + #' @noRd 6 30 find_replace_in_file <- function(from, to, file, fixed = TRUE) { 7 31 x <- readLines(file, warn = FALSE) 8 32 if (any(grepl(from, x, fixed = fixed))) { ··· 13 37 } 14 38 } 15 39 40 + #' Find and Replace Across Files in a Directory 41 + #' 42 + #' Applies `find_replace_in_file()` to all files in `path` matching `pattern`. 43 + #' 44 + #' @param from Pattern to replace. 45 + #' @param to Replacement text. 46 + #' @param path Directory to search recursively. 47 + #' @param pattern File name pattern passed to [base::list.files()]. 48 + #' 49 + #' @return Invisibly returns `NULL`. 50 + #' @keywords internal 51 + #' @noRd 16 52 find_replace_in_dir <- function(from, to, path, pattern) { 17 53 for (f in list.files( 18 54 path, ··· 24 60 } 25 61 } 26 62 63 + #' Find and Replace in GitHub Workflow Files 64 + #' 65 + #' Convenience wrapper around `find_replace_in_dir()` for 66 + #' GHA workflow files--used to update some steps. 67 + #' 68 + #' @param from Pattern to replace. 69 + #' @param to Replacement text. 70 + #' 71 + #' @return Invisibly returns `NULL`. 72 + #' @keywords internal 73 + #' @noRd 27 74 find_replace_in_gha <- function(from, to) { 28 75 find_replace_in_dir( 29 76 from = from,