library(tidyverse)
library(tidyverse)
library(here)
# --- SMART DATA LOADER ---
# Logic: If your data exists, we use it. If not, we show a sample.
my_file <- "data.csv"
file_path <- here("data", my_file)
if (file.exists(file_path)) {
# REAL DATA MODE
raw_data <- read_csv(file_path)
names(raw_data) <- tolower(gsub("[^[:alnum:]]", "_", names(raw_data))) # Basic clean_names
print(paste("SUCCESS: Loaded real data from", my_file))
} else {
# SAMPLE MODE (Demo)
# This section runs if you haven't added your file yet, so you can see the outputs.
print(paste("NOTE: '", my_file, "' not found. Generating sample data for demonstration."))
set.seed(42)
raw_data <- data.frame(
id = paste0("ID_", 1:50),
age = round(rnorm(50, 21, 2)),
gender = sample(c("Male", "Female", "Non-binary"), 50, replace = T),
anxiety_score = sample(1:7, 50, replace = T)
)
}[1] "NOTE: ' data.csv ' not found. Generating sample data for demonstration."
# Preview
head(raw_data) id age gender anxiety_score
1 ID_1 24 Female 6
2 ID_2 20 Male 7
3 ID_3 22 Female 3
4 ID_4 22 Male 6
5 ID_5 22 Female 5
6 ID_6 21 Non-binary 1