Although I’ve been writing the last few weeks about Power BI, the rest of my time during the last month has been focused on wrapping up my latest course for Pluralsight, “Getting Started with R in the Microsoft Data Platform,” which will hopefully release later this month.
The final module of this course, however, covers working with R in Power BI, so I have had a lot of Power BI on the brain lately, plus a couple of client projects for good measure!
Because this latest Pluralsight production is a “Getting Started” style of course, I can’t cover absolutely everything there is to know about Power BI and R. Just the basics, but enough to get you started. But I wanted to explore a capability in some more detail, so I thought I’d add a little bonus material for the course as one or more blog posts.
What’s the problem?
As I was putting together an example of using an R script as a Power BI data source, I ran into some issues on my development machine that was frankly driving me crazy. When I tried to run the query in Power BI with my R script (that ran successfully in the IDE, by the way), I kept getting this message:
DataSource.Error: ADO.NET: R script error.
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : namespace 'scales' 0.3.0 is being loaded, but >= 0.4.1 is required Error: package or namespace load failed for 'rnoaa' Execution halted
How to troubleshoot?
I had correctly set my R home directory in the Options dialog box.
I uninstalled and reinstalled the scales package to get a newer version. I tried to install from a different repository. No change.
I confirmed that I had installed the correct version of the scales package on which my R script indirectly relied:
Then I decided to try a super simple R script in Power BI to see exactly what library path Power was using:
Note carefully the R home directory displayed at the bottom of the dialog box: c:\program files\microsoft\r_client\r_server. Unsurprising, really, as this is what I configured in the R Scripting options.
And yet – look here! A clue!
So I resolved my problem by adding in a line at the top of my script:
.libPaths(.libPaths()[3])
Problem solved!
You might need a different index in your environment, but the key here is to specifically set the path you want Power BI to use explicitly.
The moral of the story is that despite the home directory setting, the default libPaths value might not be what you expect and affects whether your R script can execute. Maybe I’m unusual because I have a variety of environments on my computer, for a variety of reasons, but hopefully this little tidbit is useful to someone!
9 Comments
[…] Stacia Varga troubleshoots an issue integrating Power BI with R: […]
[…] my last post, I described a problem I had working with an R script in Power BI for which the cause was not […]
[…] As I was working on the last module of this course, I had an environment with a mix of R libraries on it which led me to encounter an issue in Power BI that puzzled me for a bit. The Home Directory setting didn’t behave as I expected, which led me to write a post that describes how to determine which R library tree is in use. […]
GREAT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! THANKS!!!!
So I’m not the only one this has driven nuts! Thanks for the explanation. Is there a way to use your libPaths trick for R visuals, not scripts? If I use lib.loc to point to the correct library path on my PC, then the R chart won’t work once published to the PBI service.
Same here! Really Really frustrated… it would be nice if they made it a little more clear the version that is needed for the servcie too… you need 3.4.4!
Thank you!!! I had been searching for this simple solution all this week.
Glad to help!
Stacia thank you for this!