# WARNING - Generated by {fusen} from dev/flat_kwb_simulate_inflow.Rmd: do not edit by hand # nolint: line_length_linter.


#' Rename Columns in a Data Frame
#' 
#' This function does the same thing as kwb.utils::catIf(),
#' but it is bundled with *ambre* to avoid a hard dependency on the 
#' unmaintained package.
#' 
#' Rename columns in a data frame giving tupels of original name and substitute
#' name as named elements in list "renames"
#' 
#' @param x data.frame
#' @param renamings list with named elements each of which defines a column
#'   rename in the form <old-name> = <new-name>
#' @return \emph{dframe} with columns renamed as specified in \emph{renames}
#' @references
#'   Sonnenberg H (2024). kwb.utils: General Utility Functions Developed at KWB. R package version 0.15.0
#'   URL: \url{https://github.com/kwb-r/kwb.utils}
#'   (MIT Licence)
#' @noRd
#' 
#' @examples
#' # Example usage of renameColumns
#' df <- data.frame(
#'   old_name1 = 1:3,
#'   old_name2 = letters[1:3],
#'   old_name3 = c(TRUE, FALSE, TRUE)
#' )
#'
#' # Define renaming rules
#' renamings <- list(
#'   old_name1 = "new_name1",
#'   old_name2 = "new_name2"
#' )
#'
#' # Rename columns
#' renamed_df <- renameColumns(df, renamings)
#'
#' # Print results
#' print("Original data frame:")
#' print(df)
#'
#' print("Renamed data frame:")
#' print(renamed_df)
renameColumns <- function(x, renamings = NULL)
{
  if (is.null(renamings)) {
    
    return(x)
  }
  
  columns <- names(x)
  
  for (column in names(renamings)) {
    
    columns[columns == column] <- renamings[[column]]
  }
  
  structure(x, names = columns)
}
