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

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
Power BI DataViz World Championships

Power BI Dataviz World Championships

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

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.