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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! 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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.