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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
annucsb
Frequent Visitor

R script as data source in Power BI Desktop

I want to use an R  script to connects to an API, and extract data into a data frame.  The script is executing in R studio but I get the follwing error in power BI desk top.

Details: "Exception of type 'Microsoft.Analytics.Modules.R.ErrorHandling.RException.Primitives.NotValidRDataException' was thrown."

 

I created a very simple script just to test the R script as a data source and I get the same error.  

steps to reproduce

1. start power bi desk top

2. get data > R script > click connect

3. In the  R Script dialog enter df <- c(1,2,3). 

4. click o.k. 

Result:

Unable to Connect

We encountered an error while trying to connect. 

Details: "Exception of type 'Microsoft.Analytics.Modules.R.ErrorHandling.RException.Primitives.NotValidRDataException' was thrown."

 

The script editor shows the script will run with the following R installation c:\program files\R\R-3.6.0.

1 ACCEPTED SOLUTION
annucsb
Frequent Visitor

Thank you for the reply.  The problem was with R version R-3.6.0. 

 

Here is the fix. File > Options and Settings > R scripting > select a lower version of R e.g. C:\Program Files\R\R-3.5.0

 

I can now process the results of the API call in R and connect the script to Power BI as a data source. 

 

 

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

I posted an alternative solution here: https://community.powerbi.com/t5/Issues/R-Source-and-Scripts-in-Power-Query-do-not-work-for-R-versio...

 

TLDR;

add this as the first row in the R script:

Sys.setenv(R_DEFAULT_SERIALIZE_VERSION="2", R_DEFAULT_SAVE_VERSION="2")

Many thanks, works for my R-4.0.2 installation with Power BI Desktop.

 
 
 
 
 
annucsb
Frequent Visitor

Thank you for the reply.  The problem was with R version R-3.6.0. 

 

Here is the fix. File > Options and Settings > R scripting > select a lower version of R e.g. C:\Program Files\R\R-3.5.0

 

I can now process the results of the API call in R and connect the script to Power BI as a data source. 

 

 

Anonymous
Not applicable

Just wanted to say thank you!! This worked for me as well.

v-xicai
Community Support
Community Support

Hi @annucsb ,

 

Based my test in Power BI Desktop, the R Scrip works fine for connect to data source using the code " iris_raw <- iris ".

 

7.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

8.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Please check if you have installed an R IDE on your local computer.

 

9.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

You can learn more go through the links: https://www.red-gate.com/simple-talk/sql/bi/power-bi-introduction-working-with-r-scripts-in-power-bi...

                                                                         https://docs.microsoft.com/en-us/power-bi/desktop-r-ide

Please understand that this link is provided “AS IS” with no warranties or guarantees of content changes, and confers no rights.

 

Best Regards,

Amy

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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