Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

0

R Visual will not load

I'm trying to create an R Visual for the first time in Power BI Desktop and get the message:

 

Warning message:
In options(stringsAsFactors = TRUE) :
'options(stringsAsFactors = TRUE)' is deprecated and will be disabled
Error in setwd("C:/R/WorkingDir") : cannot change working directory

Initially when I create the R visual and add fields, it looks okay and generates the script:

 

# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script:
# dataset <- data.frame(area, val, lci, uci, areagroup, label)
# dataset <- unique(dataset)
# Paste or type your script code here:
 
As soon as I enter any R code below this, no matter what it is, Power BI shows 'Can't display the visual' and returns the error message above.
 
When I go to the R scripting options in Power BI, it has auto-detected my version of R and R Studio correctly:
Detected R home directories: C\:Program Files\R\R-4.2.3
Detected R IDEs: R Studio
 
I can't work out where the setwd("C:/R/WorkingDir") error is coming from or how to fix it. Help appreciated.
Status: Delivered
Comments
Anonymous
Not applicable

Hi  @david53 ,

 

The error message Error in setwd("C:/R/WorkingDir") : cannot change working directory is indicating that R is unable to change the working directory to the specified path. This could be due to a few reasons:

The directory “C:/R/WorkingDir” does not exist. Please ensure that the directory exists and you have the necessary permissions to access it.
The path to the directory is not correctly formatted. In R, you should use forward slashes (/) or double backslashes (\\) as the path separator1. So, you can try setwd("C:/R/WorkingDir") or setwd("C:\\\\R\\\\WorkingDir").
If you’re not sure about the current working directory, you can use the getwd() function in R to get it. If you want to change the working directory in a more user-friendly way, you can use setwd(choose.dir()) which will open a dialog for you to choose the directory.

 

r - Having trouble setting working directory - Stack Overflow

Create Power BI visuals using R - Power BI | Microsoft Learn 

 

Best regards.
Community Support Team_Caitlyn

 

david53
Regular Visitor

Thank you. I created a folder with the path C:/R/WorkingDir and it now works.

 

 

Anonymous
Not applicable

 

Thank you for sharing, for other users with similar experiences you can check the comments below. This thread will now be closed.

 

Best regards.
Community Support Team_ Caitlyn