Ahmed Oussous
Ahmed Oussous

Reputation: 41

saving arabic data as csv file

Please I have a DataFrame which contains arabic data , I want to save it as csv file ( or .text), but when I try I have a problem with encoding arabic data . I read my data like this : cname=readLines('C:/Users/Ahmed/Desktop/Bureau/arabic data R/cnn-arabic-utf8/cnn-arabic-utf8/spt/sportcnnAr08sport (2).html.txt',encoding='UTF-8')

I try to save it with different ways :

con<-file('C:/Users/ahmed/Desktop/test.csv',encoding="utf8")
write.csv(clust.df ,file=con)

save(clust.df , file = "C:/Users/ahmed/Desktop/clust.txt")

write.csv(clust.df, file = "C:/Users/ahmed/Desktop/clust.txt",fileEncoding='UTF-8')

the output is always :

"<U+0623><U+062D><U+0627><U+0644><U+062A>",1

thank you in advance

Upvotes: 3

Views: 1378

Answers (2)

user3729199
user3729199

Reputation: 85

I am not 100% sure But i am 99% sure :) that CSV file or txt file don't retain character encoding. So i will suggest that try with Excel File (just to test if excel is showing correct data or not)

Upvotes: 0

Assem
Assem

Reputation: 12107

Try this:

testfile <- "C:/Users/ahmed/Desktop/test.csv"
log <- function(msg="") {
  con <- file(testfile, "a")
  tryCatch({
    cat(iconv(msg, to="UTF-8"), file=con, sep="\n")
  },
  finally = {
    close(con)
  })
}

Upvotes: 1

Related Questions