1

I want to import data to Power BI using R script (via Get Data -> Other-> R script).

However, the final imported dataset have wrong encoding for character (string) type of columns.

For example, if I use the following sample R script:

library(data.table)

dt<-data.table(str=c("Весна","Лето","Осень","Зима","И снова весна"),num=seq(1,5))

Imported dataset:

Column "str" has wrong encoding here

If I try to add Encoding(dt$str)<-"UTF-8" to the R script code, I get this error:

"Unable to translate bytes [C2] at index -1 from specified code page to Unicode."

I want to use R script because I need to do some calculations and merge several big datasets and use the merged outcome in Power BI visualization afterwards. (just pure visualization purpose only)

With other symbols it's even worse. For instance, let's try out this

dt<-data.frame(str=c("Көктем","Жаз","Күз","Қыс","Алақай, көктем келді!"),num=seq(1,5))

It even does not import anything, just throws error:

ADO.NET: R script error

rScriptWrapper_options = getOption('save.image.defaults') save(list = rScriptWrapper_dataFrames, file = "globalEnv.rdata

However, I don't get such errors neither in RStudio nor in R GUI, so I doubt the problem lays in R.

Is there any way to change encoding in such cases?

Asayat
  • 645
  • 10
  • 23

1 Answers1

1

I am very new with power BI but maybe this link can help you out.

https://community.powerbi.com/t5/Developer/R-script-Getting-Error-Unable-to-translate-bytes/m-p/138210#M4770

Fearcoder
  • 753
  • 3
  • 15
  • 47
  • Thank you very much! It helps me with Cyrillic letters, but I still encounter problems with non-Cyrillics ones :( – Asayat May 15 '17 at 09:53
  • I get unexpected string constant error using stringi library and rScriptWrapper_options error in prior case (without stringi) – Asayat May 15 '17 at 10:03
  • Have a look at this stackoverflow post http://stackoverflow.com/questions/13377206/unexpected-string-constant – Fearcoder May 15 '17 at 10:36
  • I'm afraid the problem is not in R itself. It runs ok in Rstudio and in RGui, I don't know why it throws error while importing pure dataset (without proper encoding) in first place. I guess the main issue is that some characters are seen like - and viola you got the error. Str_encode doesn't help with those special characters – Asayat May 15 '17 at 10:43