Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
I am trying to use an R script as a data source for Power BI. I am a regular user of R but am new to Power BI.
When all the datasets that are imported by the R script are from SQL databases I can import the resulting dataframes from the R script fine, however I have a script that reads from a .csv file that Power BI's R session can't find, which results in the error:
Error: 'times_of_day_grid.csv' does not exist in current working directory ('C:/Users/MyUserName/RScriptWrapper_ac2d4ec7-a4f6-4977-8713-10494f4b0c4f').
The .pbix file and the R script are both stored in the same folder as the csv
I have tried manually setting the wd by inserting into the script:
setwd("C:/Users/MyUserName/Documents/R/Projects/This Project Folder")
But this just results in the message
"Connecting - Please wait while we establish a connection to R"
Which later becomes:
Unable to connect
We encountered an error while trying to connect.
Details: "ADO.NET: R execution timeout. The script execution was terminated, since it was running for more than 1800000 miliseconds."
The R script itself takes around a minute to run in RStudio. Any ideas as to how I can edit my script (or the settings in Power BI) to get around this? (I know I can import the csv as a source separately but I don't actually want it as a data source, I just want the resulting dataframe created by the R script).
Hi @RMel ,
Is this problem solved?
If it is solved, please always accept the replies making sense as solution to your question so that people who may have the same question can get the solution directly.
If not, please let me know.
Best Regards
Icey
Hi @RMel ,
I have tested on my side and it works well.
csvfile <- read.csv("D:\\CSVFile.csv")
library(rio)
csvfile <- import("D:\\CSVFile.csv")
Please check limitations: Run R scripts in Power BI Desktop.
Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi Icey,
Thanks so much for your reply!
I have made sure I use the full working directory for the csv path and there are no interactive parts of the script that require user input. The script takes around 3 minutes to run in RStudio so I doubt it would take over 30 minutes in PowerBI. All of the data I would want to import is in data frames created by the script, and the data types for the columns should all be in factor, character, numeric or POSIXct format.
I had assumed that the problem was due to the csv import rather than the post-import data processing but it seems like that may not be the case, I will try creating a minimal version of the script that just involves importing the CSV by itself and if this works then gradually adding the rest of the processing steps to check where the problem is.
User | Count |
---|---|
101 | |
90 | |
80 | |
71 | |
69 |
User | Count |
---|---|
114 | |
97 | |
97 | |
73 | |
72 |