#' replace in multiple files using regular expression
#' @author lgm
#' @param dir directory of the files
#' @param ext extension of files
#' @param regexStr regular expression strings
#' @param replace logic value
#' @return result information
#' @export
#' @examples
#'dir <- "~/tmp/Chapter_3"
#'ext <- "*.ipynb$" # exclude files with ~
#'pat <- ""
#'replace = ""
replace_mul_files <- function(dir,ext,pat,replace){
suppressWarnings(suppressPackageStartupMessages({
library(stringr)
library(tidyverse)
}))
files <- list.files(dir,pattern = ext)
file = files[2]
replace_one_file <- function(filename,pat,replace){
f <- file.path(dir,filename)
system(glue::glue("perl -pi -w -e 's/{pat}/{replace}/g;' {f}"))
return('well done')
}
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.