I have an .RData file to read on my Linux (UTF-8) machine, but I know the file is in Latin1 because I\'ve created them myself on Windows. Unfortunately, I don\'t have access
following up on previous answers, this is a minor update which makes it work on factors and dplyr's tibble. Thanks for inspiration.
fix.encoding <- function(df, originalEncoding = "UTF-8") {
numCols <- ncol(df)
df <- data.frame(df)
for (col in 1:numCols)
{
if(class(df[, col]) == "character"){
Encoding(df[, col]) <- originalEncoding
}
if(class(df[, col]) == "factor"){
Encoding(levels(df[, col])) <- originalEncoding
}
}
return(as_data_frame(df))
}