How to use R packages in Power BI? - r

I have plotted the graph using a code in R using library function which is part of certain package.
I want to use this code in powerbi to plot the graph. But I am not able to add the package (library function) in power bi?

For a Power BI Desktop scenario, it calls the R Installation specified in the Power BI Options. So you need to add the packages you want via that R Installation.
For an app.powerbi.com scenario, you are limited to the list of packages they support, ref:
https://powerbi.microsoft.com/en-us/documentation/powerbi-service-r-visuals/

Just to clarify, are you trying to install packages or add packages that you already have into R?
Unfortunately Power BI isn't an IDE for the R language, so you will need to install the packages that you want via your R IDE or command prompt.
If you are trying to use packages that are already installed on your machine, for example, the package plotrix, then you can use the R script editor in the Visualisations tab like this:
require(plotrix)
or
library(plotrix)
Please post an update to show if this has helped you. :)

Was just now gone through the same problem: everything was loading fine except the visual created with R which required me to use ggplot2 and it was giving an error saying
there is no package called ggplot2
In order to solve it, opened RStudio and in the console ran
install.packages("ggplot2")
Then, went back to PowerBI and clicked "Atualizar" (which means "Update" in portuguese)
and the visual showed up without any errors.

Related

Trying to load a library

This is my first time using R and I was wondering what to do. I thought I installed these two packages but I got this message after I tried to run the library.
What I see when I try to run the code:

Link Project and R Version

I have two different versions of R installed, one which is up to date and which I use for all my regular R coding (needs to be up to date so that I can use various updated and new packages) and one which I use to access OLAP cubes (needs to be the R Client from Microsoft, because this is the only one which supports the olapR package, and which currently uses R version 3.4.3).
Since, in theory, I only have to access the OLAP cube once a month, I "outsourced" this task to a different RStudio project, in which I download and save the required data for all other projects. Hence, all other projects never require the olapR package to be installed and can and will be run in the up to date R version.
Now, ideally I would like to link my R version to my projects, so that I do not have to change my global R version and restart RStudio every time I access the OLAP cube or work on this data retrieval project (and then switch it back). However, I could not find any options in RStudio to achieve this result.
There are a few threads out there describing the same problem, but with no satisfactory answer in my opinion:
https://support.rstudio.com/hc/en-us/community/posts/200657296-Link-Project-and-R-Version
Rstudio project using different version of R
I also tried looking for a different package than olapR but with similar functionality, but could not find anything except X4R, which seems outdated and does not work for me (https://github.com/overcoil/X4R). Sadly, I am also unable to directly access the databases which the OLAP cube uses for its results, so I cannot go "around" it.
I am happy for any help or suggestions you can offer, whether it is a general workaround to link a project to a specific R version or the (less helpful for the community) solution of accessing the OLAP cube in a different way.
Thanks in advance!
Using the answer from MrGumble I created a .bat file that will execute my .R file using the desired R installation. Even though it is not the answer I thought I would get, I think it is an even better solution to the problem.
For all facing a similar issue, here is the .bat file (never created one before, so also had to google how to do it and I guess some might be in the same position):
#echo off
title Getting data for further processing in R
echo Retrieving OLAP data
echo.
"C:\Program Files\Microsoft\R Client\R_SERVER\bin\Rscript.exe" "C:\Users\me\Documents\Projects\!Data\script.R"
echo.
echo Saved data
echo.
pause
Thanks again to MrGumble for his help.
Skip RStudio.
RStudio is really just an editor (albeit powerful and useful) editor, which starts an R console for you (and the surrounding PATH variables, library locations, etc.).
If your monthly task only requires you to run the R-script (or a bit of interactive work), you can simply execute your preferred version of R from the command line and have it run your R script. E.g.
C:\Users\me>"C:\Program Files (x64)\Microsoft R\bin\Rscript" myscript.R
You might have to define some PATH variables so that the older R doesn't look for packages in the newer R's libraries, but that depends entirely on your current setup.

R: Is there a way to get the sessionInfo/packages of other session R?

Imagine that I open two session R.
In the first (R1) I loaded the package dplyr.
Now, my questions is, is there way to get the sessionInfo/packages loaded in R1
through R2??
UPDATE:
I am writing a R help system in Atom editor. Atom editor currently not support the function help of R. So i am creating one. And to find the help of the function you need to search into packages where this function is, the best way is know what packages are loaded in your current session R. And that is my difficult. One way to solution this is to forgett the loaded packages and search in all installed packages, but it is to slowly if you have a lot of packages installed.
So in my script R i have a line that has this code:
pkg <- .packages() # all packages loaded in this currently session
But when I run this script R1 in other script R2, it not get the packages loaded in the currently script R2, but the script R1.
Use the Services API to interact with Hydrogen
The following details interacting with other packages in atom: http://flight-manual.atom.io/behind-atom/sections/interacting-with-other-packages-via-services/
Hydrogen is an interface to a jupyter kernel. It's is maintaining the session with the kernel, and it has a plugin API currently which you could use to get the connection information to the backing kernel. https://nteract.gitbooks.io/hydrogen/docs/PluginAPI.html. Using that you could send your call to packages().
There is also r-exec, but I believe that's Mac only. In that case, you could get the

how to load R packages in Power BI [duplicate]

I have plotted the graph using a code in R using library function which is part of certain package.
I want to use this code in powerbi to plot the graph. But I am not able to add the package (library function) in power bi?
For a Power BI Desktop scenario, it calls the R Installation specified in the Power BI Options. So you need to add the packages you want via that R Installation.
For an app.powerbi.com scenario, you are limited to the list of packages they support, ref:
https://powerbi.microsoft.com/en-us/documentation/powerbi-service-r-visuals/
Just to clarify, are you trying to install packages or add packages that you already have into R?
Unfortunately Power BI isn't an IDE for the R language, so you will need to install the packages that you want via your R IDE or command prompt.
If you are trying to use packages that are already installed on your machine, for example, the package plotrix, then you can use the R script editor in the Visualisations tab like this:
require(plotrix)
or
library(plotrix)
Please post an update to show if this has helped you. :)
Was just now gone through the same problem: everything was loading fine except the visual created with R which required me to use ggplot2 and it was giving an error saying
there is no package called ggplot2
In order to solve it, opened RStudio and in the console ran
install.packages("ggplot2")
Then, went back to PowerBI and clicked "Atualizar" (which means "Update" in portuguese)
and the visual showed up without any errors.

Can't get madlib.forest_train() in Rstudio by using PivotalR library

I have configured RStudio to run R code natively on Greenplum. I have searched online but I couldn't find answer to the problem I am facing at the moment.
I have imported the library(PivotalR) and library(RPostgreSQL). But, when I type madlib it just comes up with few of the functions:
The Greenplum database has also been configured with Madlib functions including madlib.forest_train, which does not show up in RStudio. I am assuming it has something to do with the PivotalR package for RStudio. Is there a way to make the forest_train work directly from RStudio?

Resources