Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Anonymous
Not applicable

R script Getting Error Unable to translate bytes

Hello All,

I am trying to ger the twitter data using R script in power bi desktop.

Here is the script that i have used to get the twitter data.

library(twitteR)
source("authenticate.R")
tweets <- searchTwitter("Virat",n = 100,lang = "en")
tweetsdf <- twListToDF(tweets)

Details: "Unable to translate bytes [ED][A0] at index 127 from specified code page to Unicode."

 

It is running fine and am able to get the tweets in R studio, but not in Power Bi R script.

 

Please suggest me.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @KumarDarmesh

 

I have solved this issue by using stringi package.

here is the script that i have used.

 

library(twitteR)
library(stringi)

tweets <- searchTwitter(search_term, number_of_tweets )
#convert received data to something PowerBi understands
df_tweets <- twListToDF(tweets)

#column clean
df_tweets$text <- stri_encode(df_tweets$text, "", "UTF-8")

It cleans the column which are not understandable.

View solution in original post

3 REPLIES 3
KumarDarmesh
Helper IV
Helper IV

Could you post the completed code? I did download the twitteR and OATH package, however not yet to run your R script.

Anonymous
Not applicable

Hi @KumarDarmesh

 

I have solved this issue by using stringi package.

here is the script that i have used.

 

library(twitteR)
library(stringi)

tweets <- searchTwitter(search_term, number_of_tweets )
#convert received data to something PowerBi understands
df_tweets <- twListToDF(tweets)

#column clean
df_tweets$text <- stri_encode(df_tweets$text, "", "UTF-8")

It cleans the column which are not understandable.

Anonymous
Not applicable

Hi @Anonymous ,

 

I am using the same R library to extract tweets in powerBI . My R script is working fine when the search_term is hardcoded. But when I am trying to create an invoked function to pass the search_term as a parameter it gives the following error. 

 

An error occurred in the ‘’ query. DataSource.Error: ADO.NET: R script error.
During startup - Warning message:
In setJsonDatabasePath(system.file("extdata/capabilities.json",  :
  bytecode version mismatch; using eval
Error: unexpected symbol in:
"rScriptWrapper_options = getOption('save.image.defaults')
save(list = rScriptWrapper_dataFrames, file = "globalEnv.rdata"
Execution halted

Details:
    DataSourceKind=R
    DataSourcePath=R
    Message=R script error.
During startup - Warning message:
In setJsonDatabasePath(system.file("extdata/capabilities.json",  :
  bytecode version mismatch; using eval
Error: unexpected symbol in:
"rScriptWrapper_options = getOption('save.image.defaults')
save(list = rScriptWrapper_dataFrames, file = "globalEnv.rdata"
Execution halted

    ErrorCode=-2147467259
    ExceptionType=Microsoft.PowerBI.Scripting.R.Exceptions.RScriptRuntimeException

I am very new to PowerBI and hence trying a  lot to solve this issue. I really appreciate any suggestion regarding this. I am also attaching the R script for creating the invoked function.

(Name as text) as table=>
let
    
  Source = R.Execute(" #(lf)   library(twitteR)
                         #(lf)   library(stringi)
                         #(lf)   consumer_key <- ""8R96HfpMmwog1w4V0f6HrfwS9"" 
                         #(lf)   consumer_secret <- ""Smun1VSNdn30P5HfvAJ4AR8XSmqOevkGCvwQ2RJpXrHptRTEui""
                         #(lf)   access_token <- ""1306483171-2I5rsnK7AvYStXEja7lDu9AAI7ftuv6CvcbhhW0""
                         #(lf)   access_secret <- ""SlsagLzQfoaE0VzocM6ycFLqSk0PtImwekwENZt339yej""
                         #(lf)   setup_twitter_oauth(consumer_key, consumer_secret, access_token, access_secret)
                         #(lf)   str1 <- ""#""
                         #(lf)   str2 <- ""&Name&""   (passing parameter here)
                         #(lf)   search_term <- paste(str1,str2,sep="") 
                         #(lf)   number_of_tweets <- 100
                         #(lf)   language <-'en'
                         #(lf)   tweets <- searchTwitter(search_term, number_of_tweets,language)
                         #(lf)   df_tweets <- twListToDF(tweets)
                         #(lf)   df_tweets <- df_tweets[,c('text','favorited','favoriteCount','created','retweetCount',
                                                                                              'isRetweet','retweeted')]
                         #(lf)   df_tweets$text <- stri_encode(df_tweets$text, '', 'UTF-8')"),
    df_tweets1 = Source{[Name="df_tweets"]}[Value]
in
    df_tweets1

Thank you.

 

 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

Find out what's new and trending in the Fabric Community.

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

Check out the November 2024 Power BI update to learn about new features.