cancel
Showing results for 
Search instead for 
Did you mean: 

R script runs query more than once

I have a file with 21,076 rows and 2 columns: “id” and “text”. I am trying to use R scripts to connect to Azure Cognitive Services API and apply Language detection to the “text” column. When I run my script in R Studio it works fine on the 21,076 rows (Due to limitations of the API Im sending chunks of 1,000 messages and then appending the results in R to an output dataframe to be used in PowerBI).
 
However, when I use PowerBI R scripts, the query seems to run the R script multiple times (Im saving in a .csv each time the code calls the API). I can see internally that the R code is sucessfully generating the output data frame of 21,076 rows but strangly the query is running the script AGAIN, this second time generates 9,000 rows (the first 9 chunks I’m sending to Azure).
 
Is it Power Query running my R script more than once? why?

Status: Needs Info
Comments
Super Contributor

@jrecasens

 

Do you have a sample PBIX file which can be used to repro the same issue on my side? I'd like to have a try locally.

And this thread maybe related to the problem.

 

Best Regards,

Herbert

Established Member
Status changed to: Needs Info
 
Frequent Visitor

@v-haibl-msft

Attached you can find the files:
https://1drv.ms/f/s!ApFP03_iPLLTg44qzx0JTucsro8Unw

 

You need to change two things: the folder parameter in the .pbix file and also update your API key in the R code. You can create a "Text Analytics API" key here:
https://azure.microsoft.com/en-us/try/cognitive-services/?api=text-analytics

The .pbix has a query that references the R code (code.R file). The resulting dataset (output.txt) should have 9,181 rows but in PowerBI, chunks of data are sent multiple times, as shown in the log.txt output.

To test it in R Studio just un-comment the first lines of code.

Frequent Visitor

Hello, do you have news regarding this issue? thank you.

Frequent Visitor

Did you ever find a solution for this? I just posted a similar issue in the community forum: 

Query Containing R Script Algorithm is Evaluated Twice on Refresh

Frequent Visitor

I did NOT find a solution. I have updated the link (with my example) if its helps.

Frequent Visitor

The consistencies in our methods are that we both use a parameter query, and we both define a custom table other than the default "dataset" in our R.exectue() call. See my forum post for a simple reproduction of our issue.