R/utils.R

Defines functions convert_encoding

#' Clean mis-encoded columns in data frame
#'
#' Internal function for cleaning mis-encoded characters in non-typical IMGW files
#' @param df data frame
#'
#' @keywords internal
#' @noRd

convert_encoding = function(df) {
  df[] = lapply(df, function(col) {
    if (is.character(col)) {
      iconv(col, from = "CP1250", to = "UTF-8")
    } else if (is.factor(col)) {
      factor(iconv(as.character(col), from = "CP1250", to = "UTF-8"))
    } else {
      col
    }
  })
  return(df)
}

Try the climate package in your browser

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

climate documentation built on June 8, 2025, 11:09 a.m.