R transformation from matrix to dataframe - utf-8 encoding gets lost

485 views Asked by At

:)) So, I connected to a DB using JDBC

conn <- dbConnect(drv, "jdbc:oracle:thin:...", "DJULIA", "..."
                    , DBMSEncoding='UTF-8')

After extracting Information from the database, using a SQL Query, I had the problem, that the characters in the data.frame are not encoded with the right Encoding, so I wrote a little script to save the information from the data.frame into a matrix and encoding it accordingly.

miau <- dbGetQuery(conn, "select * from table
where product_id = x")
  miau1 <- t(rep(0,length(miau)))
  i <-1
  while (i <= length(miau))
  {

  if(is.character(miau[,i]))
  {
    miau1[i] <- enc2utf8(miau[,i])
  }
  else
    {
      miau1[i] <- miau[,i]
    }
  i<-i+1;
  }

This works perfectly fine, I just don't understand: Why doesn't the character in the data.frame get shown in the right format? Here is an example of how it looks in the data.frame:

CLIENT_ID PRODUCT_ID BRAND               SEASON           NAME        NAME_EN 
1         1   56527401 oodji Îñåíü-çèìà 2013/2014 Êóðòêà êîæàíàÿ Êóðòêà êîæàíàÿ

and as matrix

     [,1] [,2]       [,3]    [,4]                   [,5]             [,6]
[1,] "1"  "56527401" "oodji" "Осень-зима 2013/2014" "Куртка кожаная" "Куртка кожаная" 
0

There are 0 answers