Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowGet inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.
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/
Rstudio
Solved! Go to 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/
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.
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/
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.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
86 | |
79 | |
42 | |
40 | |
35 |