Forum Discussion

otravers's avatar
otravers
Community Champion
9 years ago
Solved

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 furthe...
  • otravers's avatar
    otravers
    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/