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:


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!