Forum Discussion
Getting Power BI Desktop to see R packages?
- 9 years ago
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/
- svarghese8 years agoAdvocate I
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.