R/comma_to_semicolon.R

Defines functions comma_to_semicolon

Documented in comma_to_semicolon

#' Replaces commas by semicolons inside of a file
#'
#' Replaces all commas by semicolons in a file and overwrites the file. The
#' function is actually capable of replacing other strings too, but that is not
#' the standard.
#'
#' @param file the file to modify.
#' @param pattern the string to replace.
#' @param replacement the replacement.
#' @keywords substitute, replace
#' @export
#' @examples
#' table <- cbind(1:10, LETTERS[1:10])
#' # this will create a file in the working dir
#' write.csv(table, file = "comma_to_semicolon_example.csv")
#' read.csv("comma_to_semicolon_example.csv")
#' comma_to_semicolon("comma_to_semicolon_example.csv")
#' read.csv("comma_to_semicolon_example.csv")

comma_to_semicolon <-
  function(file,
           pattern = ",",
           replacement = ";") {
    corrected <- gsub(pattern, replacement, readLines(file))
    writeLines(corrected, con = file)
  }
mtcruz/mtcruzr documentation built on Dec. 26, 2019, 11:04 p.m.