R/h_replace.R

#' @title Replace a value by another
#'
#' @author P. Chevallier - Oct 2017- Nov 2020
#'
#' @details The output file is named with a re_ prefix.
#'
#' @param file File name to proceed
#' @param old.val Value to be replaced
#' @param new.val New value
#'
#' @examples \dontrun{
#'
#' f <- ts_remplace_ts(f,  NA, 0)
#' }
#'

h_replace <- function (file, old.val, new.val) {

  #initialisation
  NValue <- Station <- Sensor <- NULL
  dn <- dirname (file)
  bn <- basename (file)

  # lecture du fichier

  oldnew <- function (x , old.val, new.val) {
    if (x == old.val) x <- new.val
    return (x)
  }
  load(file)
  x <- mutate(tstab, NValue = NA)
  for (i in 1:nrow(x)) x$NValue[i] <- oldnew (x$Value[i] , old.val, new.val)

  tstab <- select(x, Date, Value = NValue, Station, Sensor)

  #ecriture fichier
  fileo <- paste0(dn,"/re_",bn)
  save(tstab, file=fileo)
  message("\nFile written: ", fileo,"\n")
  return (fileo)

}
# FIN

Try the htsr package in your browser

Any scripts or data that you put into this service are public.

htsr documentation built on Oct. 13, 2023, 5:10 p.m.