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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
otravers
Community Champion
Community Champion

Getting Power BI Desktop to see R packages?

Hi,

 

I installed RStudio and added the corrplot and stringr packages to it. They are listed and checked under User Library, and I can run str_count successfully from the console. Screenshot further below.

 

However when I try to run str_count from Power BI Desktop's R script editor, I get "can't display this visual". Clicking on See details tells me "could not find function str_count". "Detected R home directories" and "Detected R IDEs" are both properly filled in under Options > Global > R Scripting.

 

Rstudio has by default used C:\Users\{WinUserName}\Documents\R\win-library\3.3 to store my user library instead of its C:\Program Files install directory. Is this why PBI doesn't see the R packages I installed? Do you need to explicitly set the user library under the R install dir for PBI to find it?

 

I read the following entry and googled around but didn't find an answer to this question.

https://powerbi.microsoft.com/en-us/documentation/powerbi-desktop-r-visuals/

 

RstudioRstudio

 

 

------------------------------------------------
1. How to get your question answered quickly - good questions get good answers!
2. Learning how to fish > being spoon-fed without active thinking.
3. Please accept as a solution posts that resolve your questions.
------------------------------------------------
BI Blog: Datamarts | RLS/OLS | Dev Tools | Languages | Aggregations | XMLA/APIs | Field Parameters | Custom Visuals
1 ACCEPTED SOLUTION

I removed my user library, installed packages at C:/Program Files/MRO-3.3.2/library, and changed Rstudio's library path with .libPaths(). But then I realized that even after doing this, I still needed to load packages in Rstudio before I was able to use them. I thought the library would be scanned and packages were autoloaded, which turns out to be an incorrect assumption.

 

So, whether in Rstudio or from Power BI's R script editor, you need to explicitly load the package before using it:

 

library("stringr", lib.loc="C:/Program Files/MRO-3.3.2/library")
sum(str_count(dataset, "my string"))

 

Edit: the lib.loc local path will obviously not work once you publish to the cloud service. This is not necessary if the path for the R environment is properly set in Power BI Desktop settings.

 

Also, if you're going nuts because PBI is complaining about outdated packages/dependencies even though RStudio shows you have the correct (latest) version, read this:

http://blog.datainspirations.com/2018/02/02/power-bi-r-home-directory-vs-library-trees/

------------------------------------------------
1. How to get your question answered quickly - good questions get good answers!
2. Learning how to fish > being spoon-fed without active thinking.
3. Please accept as a solution posts that resolve your questions.
------------------------------------------------
BI Blog: Datamarts | RLS/OLS | Dev Tools | Languages | Aggregations | XMLA/APIs | Field Parameters | Custom Visuals

View solution in original post

3 REPLIES 3
v-huizhn-msft
Employee
Employee

Hi @otravers,

You'd better put the package and installation in the same path. And set the R home directories in the highlighted yellow background.

1.PNG

First you can load your R resource data according to here, and check if you can load it successfully. But please notice "Only data frames are imported, so make sure the data you want to import to Power BI is represented in a data frame - Columns that are typed as Complex and Vector are not imported, and are replaced with error values in the created table. ", so verify your data format.

Please let me know if you have any questions.

Best Regards,
Angelia

I removed my user library, installed packages at C:/Program Files/MRO-3.3.2/library, and changed Rstudio's library path with .libPaths(). But then I realized that even after doing this, I still needed to load packages in Rstudio before I was able to use them. I thought the library would be scanned and packages were autoloaded, which turns out to be an incorrect assumption.

 

So, whether in Rstudio or from Power BI's R script editor, you need to explicitly load the package before using it:

 

library("stringr", lib.loc="C:/Program Files/MRO-3.3.2/library")
sum(str_count(dataset, "my string"))

 

Edit: the lib.loc local path will obviously not work once you publish to the cloud service. This is not necessary if the path for the R environment is properly set in Power BI Desktop settings.

 

Also, if you're going nuts because PBI is complaining about outdated packages/dependencies even though RStudio shows you have the correct (latest) version, read this:

http://blog.datainspirations.com/2018/02/02/power-bi-r-home-directory-vs-library-trees/

------------------------------------------------
1. How to get your question answered quickly - good questions get good answers!
2. Learning how to fish > being spoon-fed without active thinking.
3. Please accept as a solution posts that resolve your questions.
------------------------------------------------
BI Blog: Datamarts | RLS/OLS | Dev Tools | Languages | Aggregations | XMLA/APIs | Field Parameters | Custom Visuals

HI

 

I had a similar issue. The following worked but is far from being the ideal soloution.

PowerBI tries to use the system user to conect with Rstudio. So I ran both powerBI and Rstudio as Adminisrator (right click on the program). I installed the required libraries in R studio into the system library using:;

install.packages('packagname','C:/Program files/R/R-3.3.3/library)

and invoked the libraries from powerBI and that worked.

Tried other ways to maintain all intercations with the username as myself but that did not work.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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