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

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
Anonymous
Not applicable

Help with r script setwd error

Hi, I am brand new to Power BI and I keep getting this error when trying to create a barplot using the r script visualization tool: Error: unexpected symbol in: ""setwd(Sys.getenv('RScriptWrapperWorkingDirectory')) graphics.off" Execution halted. It seems to be something running in the background since I do not have this strand in my code segment. Here is the relevant portion of my code segment: 


# Calculate evaluation metrics for the mean naive model
mean_naive_mae <- mean(abs(avg_predictions - test_data$target))
mean_naive_rmse <- sqrt(mean((avg_predictions - test_data$target)^2))
mean_naive_mape <- mean(abs((avg_predictions - test_data$target) / test_data$target)) * 100
mean_naive_ss_residual <- sum((test_data$target - avg_predictions)^2)
mean_naive_ss_total <- sum((test_data$target - mean(test_data$target))^2)
mean_naive_r_squared <- 1 - (mean_naive_ss_residual / mean_naive_ss_total)

# Custom formatting function
custom_format <- function(x) {
  ifelse(x >= 1000, formatC(x, format = "d", big.mark = ",", digits = 0),
         formatC(x, format = "f", big.mark = ",", digits = 4)
  )
}

# Create a data frame with the evaluation metrics for your model, the naive model, and the mean naive model
# Read the evaluation metrics data
metrics <- data.frame(
  Metric = c("MAE", "RMSE", "MAPE", "R-squared"),
  Boosted_Model = c(mae, rmse, mape, r_squared),
  Recent_Model = c(naive_mae, naive_rmse, naive_mape, naive_r_squared),
  Average_Model = c(mean_naive_mae, mean_naive_rmse, mean_naive_mape, mean_naive_r_squared),
  stringsAsFactors = FALSE
)

# Plot the evaluation metrics as a bar plot
barplot(as.matrix(metrics[, -1]), beside = TRUE, names.arg = metrics$Metric,
        main = "Evaluation Metrics", xlab = "Metric", ylab = "Value",
 
Thanks!
0 REPLIES 0

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.