Forum Discussion
R script with several dataframes
- 9 years ago
When using R scripts in Power BI Desktop, it will generate one dataset for each data frame. If you generate multiple data frames with single R script, it will generate multiple datasets and repeat the R script for each dataset. We can't access the original script and make changes applied to all datasets by updating only one script.
Also when refreshing dataset, it will run the R script again for each dataset which is very inefficient in your scenario. So I suggest you use multiple R scripts and each of them only creates one data frame.
Reference:
Running R Scripts in Power BI DesktopRegards,
You could try to:
1) Save your R code as a separate .R file
2) Call your R file in Power BI using the source() function in R
http://www.cookbook-r.com/Data_input_and_output/Running_a_script/
This may allow you to change the base code once while having all the data flow properly to each individual Power BI query.
If storing the script outside of the Power BI report is not feasible you could also store the R script as a text only query without a connection, then have your other power queries execute the script from that query.
- erchs8 years agoFrequent Visitor
This solves the problem and its a nice workaround. However, when sending the report to production, it is unclear to me how would the sourceing work.
Could you show some details what you mean by text only query? Thank you.