excel - R - SQLDF issue with special characters -


i'm having issue running sqldf in r , special characters.

here small detail of code i'm running give idea of what's going on:

first read data excel sheet (using r's xlsx package), method xlsx2 seems data correctly , characters seem showing special characters such 'Ñ'

verif_oblig <- try(read.xlsx2("my computer/filename.xlsx", sheetname = 'verif_oblig')) if("try-error" %in% class(verif_oblig))    verif_oblig <- empty() 

then start running sql query using sqldf , resulting table seems replace Ñ characters Ñ. here's query:

verif_oblig_v2 <- sqldf("   select    a.*,   case when b.estado null 'no generado'   else b.estado end estado,    case when resultado_operacion in ('exito','correcto')   'exito'    else 'sin exito'    end resultado_actual     verif_oblig left join fin2016 b    on   a.cups = b.cups_largo , a.division = b.division") 

can me find solution this?

thank much

i ended solving replacing characters bugging after sql query using gsub this:

clear_errors <- function(table, campo){ table <- as.data.frame(table) table[,campo] <- c(gsub("Ã'","Ñ",c(tabla_entrada[,campo]))) table[,campo]<- c(gsub("é","é",c(tabla_entrada[,campo]))) table[,campo]<- c(gsub("ó", "ó",c(tabla_entrada[,campo]))) table[,campo] <- c(gsub("ú","ú",c(tabla_entrada[,campo]))) table[,campo] <- c(gsub("ñ","ñ",c(tabla_entrada[,campo]))) table[,campo] <- c(gsub("Ã","í",c(tabla_entrada[,campo]))) table[,campo] <- c(gsub("o","a",c(tabla_entrada[,campo]))) return(table) 

}

it isn't elegant solution works.

i think issue happens because xlsx formats characters factors , uses different encoding sqldf them. if can find out what's going on i'd appreciate (just out of curiosity)


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -