R.Execute
The data frames an R script leaves behind, as a navigation table: the script runs in this computer's R.
Group: Python and R. Power Query M has it too: a query that uses it is written as in Power BI.
Syntax
R.Execute(script as text, optional arguments as nullable record) as table
| Parameter | Type | Description |
|---|---|---|
script | text | The R script. |
arguments | nullable record optional | Tables to hand to the script: each field becomes a data frame of that name, as Power BI's dataset. |
Returns
table. Name and Value: a row per data frame the script leaves, Value its table.
Remarks
- Every variable that holds a data frame when the script ends is a row, named after the variable.
- It needs R. OpenBI finds the R installed on the computer, or the folder set in OpenBI Studio's options; with R's arrow package the frames travel as Parquet, without it as CSV.
- A script runs only once the project allows it: OpenBI Studio asks once per project before its scripts run. Without that, the step stops with a message saying scripts are off.
- A script that fails stops the step with the end of what R printed. A script may run for 30 minutes at most.
- Python and R scripts are kept so that Power BI projects open and refresh. For analysis, OpenBI's notebooks are the place (Why no Python or R, in the docs).
Examples
A data frame made by the script
R.Execute("shops <- data.frame(Shop = c(""Oslo"", ""Bergen""), Sales = c(120.5, 95))")
Result: not shown here: the docs' build runs no scripts.
One row, shops, whose Value is the frame: Oslo 120.5 and Bergen 95.
A step's table, changed by the script
let
Source = #table(type table [Product = text, Qty = Int64.Type, Price = number], {{"Chair", 2, 60}, {"Lamp", 3, 15.5}}),
Run = R.Execute("dataset$Total <- dataset$Qty * dataset$Price", [dataset = Source])
in
Run{[Name = "dataset"]}[Value]
Result: not shown here: the docs' build runs no scripts.