romainprudhon commited on
Commit
58a6b6a
·
verified ·
1 Parent(s): f88aeda

Upload R_analysis_Romain_PRUDHON.ipynb

Browse files
Files changed (1) hide show
  1. R_analysis_Romain_PRUDHON.ipynb +518 -0
R_analysis_Romain_PRUDHON.ipynb ADDED
@@ -0,0 +1,518 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "75fd9cc6",
6
+ "metadata": {
7
+ "id": "75fd9cc6"
8
+ },
9
+ "source": [
10
+ "# **🤖 Benchmarking & Modeling**"
11
+ ]
12
+ },
13
+ {
14
+ "cell_type": "markdown",
15
+ "id": "fb807724",
16
+ "metadata": {
17
+ "id": "fb807724"
18
+ },
19
+ "source": [
20
+ "## **1.** 📦 Setup"
21
+ ]
22
+ },
23
+ {
24
+ "cell_type": "code",
25
+ "execution_count": 6,
26
+ "id": "d40cd131",
27
+ "metadata": {
28
+ "id": "d40cd131",
29
+ "outputId": "f520f27c-3e9c-470d-c36b-0267ff1c4949",
30
+ "colab": {
31
+ "base_uri": "https://localhost:8080/"
32
+ }
33
+ },
34
+ "outputs": [
35
+ {
36
+ "output_type": "stream",
37
+ "name": "stderr",
38
+ "text": [
39
+ "Installing packages into ‘/usr/local/lib/R/site-library’\n",
40
+ "(as ‘lib’ is unspecified)\n",
41
+ "\n",
42
+ "Warning message in install.packages(c(\"readr\", \"dplyr\", \"stringr\", \"tidyr\", \"lubridate\", :\n",
43
+ "“installation of package ‘forecast’ had non-zero exit status”\n"
44
+ ]
45
+ }
46
+ ],
47
+ "source": [
48
+ "install.packages(c(\n",
49
+ " \"readr\",\"dplyr\",\"stringr\",\"tidyr\",\"lubridate\",\n",
50
+ " \"ggplot2\",\"forecast\",\"broom\",\"jsonlite\"\n",
51
+ "), repos=\"https://cloud.r-project.org\")"
52
+ ]
53
+ },
54
+ {
55
+ "cell_type": "code",
56
+ "source": [
57
+ "#do above first and then Runtime → Restart session and then do:\n",
58
+ "library(readr)\n",
59
+ "library(dplyr)\n",
60
+ "library(stringr)\n",
61
+ "library(tidyr)\n",
62
+ "library(lubridate)\n",
63
+ "library(ggplot2)\n",
64
+ "library(forecast)\n",
65
+ "library(broom)\n",
66
+ "library(jsonlite)"
67
+ ],
68
+ "metadata": {
69
+ "colab": {
70
+ "base_uri": "https://localhost:8080/"
71
+ },
72
+ "id": "FR_YZUD9J_Py",
73
+ "outputId": "6b801e29-0053-469f-b4c9-05d8ead19904"
74
+ },
75
+ "id": "FR_YZUD9J_Py",
76
+ "execution_count": 1,
77
+ "outputs": [
78
+ {
79
+ "output_type": "stream",
80
+ "name": "stderr",
81
+ "text": [
82
+ "\n",
83
+ "Attaching package: ‘dplyr’\n",
84
+ "\n",
85
+ "\n",
86
+ "The following objects are masked from ‘package:stats’:\n",
87
+ "\n",
88
+ " filter, lag\n",
89
+ "\n",
90
+ "\n",
91
+ "The following objects are masked from ‘package:base’:\n",
92
+ "\n",
93
+ " intersect, setdiff, setequal, union\n",
94
+ "\n",
95
+ "\n",
96
+ "\n",
97
+ "Attaching package: ‘lubridate’\n",
98
+ "\n",
99
+ "\n",
100
+ "The following objects are masked from ‘package:base’:\n",
101
+ "\n",
102
+ " date, intersect, setdiff, union\n",
103
+ "\n",
104
+ "\n"
105
+ ]
106
+ }
107
+ ]
108
+ },
109
+ {
110
+ "cell_type": "markdown",
111
+ "id": "f01d02e7",
112
+ "metadata": {
113
+ "id": "f01d02e7"
114
+ },
115
+ "source": [
116
+ "## **2.** ✅️ Load & inspect inputs"
117
+ ]
118
+ },
119
+ {
120
+ "cell_type": "code",
121
+ "execution_count": 3,
122
+ "id": "29e8f6ce",
123
+ "metadata": {
124
+ "colab": {
125
+ "base_uri": "https://localhost:8080/"
126
+ },
127
+ "id": "29e8f6ce",
128
+ "outputId": "9af6e4c9-59d9-4475-a106-beada0b3338c"
129
+ },
130
+ "outputs": [
131
+ {
132
+ "output_type": "stream",
133
+ "name": "stdout",
134
+ "text": [
135
+ "Loaded: 1000 rows (title-level), 18 rows (monthly)\n"
136
+ ]
137
+ }
138
+ ],
139
+ "source": [
140
+ "\n",
141
+ "must_exist <- function(path, label) {\n",
142
+ " if (!file.exists(path)) stop(paste0(\"Missing \", label, \": \", path))\n",
143
+ "}\n",
144
+ "\n",
145
+ "TITLE_PATH <- \"synthetic_title_level_features.csv\"\n",
146
+ "MONTH_PATH <- \"synthetic_monthly_revenue_series.csv\"\n",
147
+ "\n",
148
+ "must_exist(TITLE_PATH, \"TITLE_PATH\")\n",
149
+ "must_exist(MONTH_PATH, \"MONTH_PATH\")\n",
150
+ "\n",
151
+ "df_title <- read_csv(TITLE_PATH, show_col_types = FALSE)\n",
152
+ "df_month <- read_csv(MONTH_PATH, show_col_types = FALSE)\n",
153
+ "\n",
154
+ "cat(\"Loaded:\", nrow(df_title), \"rows (title-level),\", nrow(df_month), \"rows (monthly)\n",
155
+ "\")"
156
+ ]
157
+ },
158
+ {
159
+ "cell_type": "code",
160
+ "execution_count": 4,
161
+ "id": "9fd04262",
162
+ "metadata": {
163
+ "colab": {
164
+ "base_uri": "https://localhost:8080/"
165
+ },
166
+ "id": "9fd04262",
167
+ "outputId": "b7c028ba-157c-4d4f-db6c-9098104adec5"
168
+ },
169
+ "outputs": [
170
+ {
171
+ "output_type": "stream",
172
+ "name": "stdout",
173
+ "text": [
174
+ "\u001b[90m# A tibble: 1 × 6\u001b[39m\n",
175
+ " n na_avg_revenue na_price na_rating na_share_pos na_share_neg\n",
176
+ " \u001b[3m\u001b[90m<int>\u001b[39m\u001b[23m \u001b[3m\u001b[90m<int>\u001b[39m\u001b[23m \u001b[3m\u001b[90m<int>\u001b[39m\u001b[23m \u001b[3m\u001b[90m<int>\u001b[39m\u001b[23m \u001b[3m\u001b[90m<int>\u001b[39m\u001b[23m \u001b[3m\u001b[90m<int>\u001b[39m\u001b[23m\n",
177
+ "\u001b[90m1\u001b[39m \u001b[4m1\u001b[24m000 0 0 \u001b[4m1\u001b[24m000 0 0\n",
178
+ "Monthly rows after parsing: 18 \n"
179
+ ]
180
+ }
181
+ ],
182
+ "source": [
183
+ "\n",
184
+ "# ---------- helpers ----------\n",
185
+ "safe_num <- function(x) {\n",
186
+ " # strips anything that is not digit or dot\n",
187
+ " suppressWarnings(as.numeric(str_replace_all(as.character(x), \"[^0-9.]\", \"\")))\n",
188
+ "}\n",
189
+ "\n",
190
+ "parse_rating <- function(x) {\n",
191
+ " # Accept: 4, \"4\", \"4.0\", \"4/5\", \"4 out of 5\", \"⭐⭐⭐⭐\", etc.\n",
192
+ " x <- as.character(x)\n",
193
+ " x <- str_replace_all(x, \"⭐\", \"\")\n",
194
+ " x <- str_to_lower(x)\n",
195
+ " x <- str_replace_all(x, \"stars?\", \"\")\n",
196
+ " x <- str_replace_all(x, \"out of\", \"/\")\n",
197
+ " x <- str_replace_all(x, \"\\\\s+\", \"\")\n",
198
+ " x <- str_replace_all(x, \"[^0-9./]\", \"\")\n",
199
+ " suppressWarnings(as.numeric(str_extract(x, \"^[0-9.]+\")))\n",
200
+ "}\n",
201
+ "\n",
202
+ "parse_month <- function(x) {\n",
203
+ " x <- as.character(x)\n",
204
+ " # try YYYY-MM-DD, then YYYY-MM\n",
205
+ " out <- suppressWarnings(ymd(x))\n",
206
+ " if (mean(is.na(out)) > 0.5) out <- suppressWarnings(ymd(paste0(x, \"-01\")))\n",
207
+ " na_idx <- which(is.na(out))\n",
208
+ " if (length(na_idx) > 0) out[na_idx] <- suppressWarnings(ymd(paste0(x[na_idx], \"-01\")))\n",
209
+ " out\n",
210
+ "}\n",
211
+ "\n",
212
+ "# ---------- normalize keys ----------\n",
213
+ "df_title <- df_title %>% mutate(title = str_squish(as.character(title)))\n",
214
+ "df_month <- df_month %>% mutate(month = as.character(month))\n",
215
+ "\n",
216
+ "# ---------- parse numeric columns defensively ----------\n",
217
+ "need_cols_title <- c(\"title\",\"avg_revenue\",\"total_revenue\",\"price\",\"rating\",\"share_positive\",\"share_negative\",\"share_neutral\")\n",
218
+ "missing_title <- setdiff(need_cols_title, names(df_title))\n",
219
+ "if (length(missing_title) > 0) stop(paste0(\"df_title missing columns: \", paste(missing_title, collapse=\", \")))\n",
220
+ "\n",
221
+ "df_title <- df_title %>%\n",
222
+ " mutate(\n",
223
+ " avg_revenue = safe_num(avg_revenue),\n",
224
+ " total_revenue = safe_num(total_revenue),\n",
225
+ " price = safe_num(price),\n",
226
+ " rating = parse_rating(rating),\n",
227
+ " share_positive = safe_num(share_positive),\n",
228
+ " share_negative = safe_num(share_negative),\n",
229
+ " share_neutral = safe_num(share_neutral)\n",
230
+ " )\n",
231
+ "\n",
232
+ "# basic sanity stats\n",
233
+ "hyg <- df_title %>%\n",
234
+ " summarise(\n",
235
+ " n = n(),\n",
236
+ " na_avg_revenue = sum(is.na(avg_revenue)),\n",
237
+ " na_price = sum(is.na(price)),\n",
238
+ " na_rating = sum(is.na(rating)),\n",
239
+ " na_share_pos = sum(is.na(share_positive)),\n",
240
+ " na_share_neg = sum(is.na(share_negative))\n",
241
+ " )\n",
242
+ "\n",
243
+ "print(hyg)\n",
244
+ "\n",
245
+ "# monthly parsing\n",
246
+ "need_cols_month <- c(\"month\",\"total_revenue\")\n",
247
+ "missing_month <- setdiff(need_cols_month, names(df_month))\n",
248
+ "if (length(missing_month) > 0) stop(paste0(\"df_month missing columns: \", paste(missing_month, collapse=\", \")))\n",
249
+ "\n",
250
+ "df_month2 <- df_month %>%\n",
251
+ " mutate(\n",
252
+ " month = parse_month(month),\n",
253
+ " total_revenue = safe_num(total_revenue)\n",
254
+ " ) %>%\n",
255
+ " filter(!is.na(month)) %>%\n",
256
+ " arrange(month)\n",
257
+ "\n",
258
+ "cat(\"Monthly rows after parsing:\", nrow(df_month2), \"\\n\")"
259
+ ]
260
+ },
261
+ {
262
+ "cell_type": "markdown",
263
+ "id": "b8971bc4",
264
+ "metadata": {
265
+ "id": "b8971bc4"
266
+ },
267
+ "source": [
268
+ "## **3.** 💾 Folder for R outputs for Hugging Face"
269
+ ]
270
+ },
271
+ {
272
+ "cell_type": "code",
273
+ "execution_count": 5,
274
+ "id": "dfaa06b1",
275
+ "metadata": {
276
+ "colab": {
277
+ "base_uri": "https://localhost:8080/"
278
+ },
279
+ "id": "dfaa06b1",
280
+ "outputId": "85005150-1d3f-4c16-ffbe-ca7b91b379ab"
281
+ },
282
+ "outputs": [
283
+ {
284
+ "output_type": "stream",
285
+ "name": "stdout",
286
+ "text": [
287
+ "R outputs will be written to: /content/artifacts/r \n"
288
+ ]
289
+ }
290
+ ],
291
+ "source": [
292
+ "\n",
293
+ "ART_DIR <- \"artifacts\"\n",
294
+ "R_FIG_DIR <- file.path(ART_DIR, \"r\", \"figures\")\n",
295
+ "R_TAB_DIR <- file.path(ART_DIR, \"r\", \"tables\")\n",
296
+ "\n",
297
+ "dir.create(R_FIG_DIR, recursive = TRUE, showWarnings = FALSE)\n",
298
+ "dir.create(R_TAB_DIR, recursive = TRUE, showWarnings = FALSE)\n",
299
+ "\n",
300
+ "cat(\"R outputs will be written to:\", normalizePath(file.path(ART_DIR, \"r\"), winslash = \"/\"), \"\n",
301
+ "\")"
302
+ ]
303
+ },
304
+ {
305
+ "cell_type": "markdown",
306
+ "id": "f880c72d",
307
+ "metadata": {
308
+ "id": "f880c72d"
309
+ },
310
+ "source": [
311
+ "## **4.** 🔮 Forecast book sales benchmarking with `accuracy()`"
312
+ ]
313
+ },
314
+ {
315
+ "cell_type": "markdown",
316
+ "source": [
317
+ "We benchmark **three** models on a holdout window (last *h* months):\n",
318
+ "- ARIMA + Fourier (seasonality upgrade)\n",
319
+ "- ETS\n",
320
+ "- Naive baseline\n",
321
+ "\n",
322
+ "Then we export:\n",
323
+ "- `accuracy_table.csv`\n",
324
+ "- `forecast_compare.png`\n",
325
+ "- `rmse_comparison.png`"
326
+ ],
327
+ "metadata": {
328
+ "id": "R0JZlzKegmzW"
329
+ },
330
+ "id": "R0JZlzKegmzW"
331
+ },
332
+ {
333
+ "cell_type": "code",
334
+ "execution_count": 6,
335
+ "id": "62e87992",
336
+ "metadata": {
337
+ "colab": {
338
+ "base_uri": "https://localhost:8080/",
339
+ "height": 82
340
+ },
341
+ "id": "62e87992",
342
+ "outputId": "533ff3fe-2c85-4312-ab04-36007d0cbe1b"
343
+ },
344
+ "outputs": [
345
+ {
346
+ "output_type": "stream",
347
+ "name": "stdout",
348
+ "text": [
349
+ "✅ Saved: artifacts/r/tables/accuracy_table.csv\n",
350
+ "✅ Saved: artifacts/r/figures/rmse_comparison.png\n"
351
+ ]
352
+ },
353
+ {
354
+ "output_type": "display_data",
355
+ "data": {
356
+ "text/html": [
357
+ "<strong>agg_record_805943657:</strong> 2"
358
+ ],
359
+ "text/markdown": "**agg_record_805943657:** 2",
360
+ "text/latex": "\\textbf{agg\\textbackslash{}\\_record\\textbackslash{}\\_805943657:} 2",
361
+ "text/plain": [
362
+ "agg_record_805943657 \n",
363
+ " 2 "
364
+ ]
365
+ },
366
+ "metadata": {}
367
+ },
368
+ {
369
+ "output_type": "stream",
370
+ "name": "stdout",
371
+ "text": [
372
+ "✅ Saved: artifacts/r/figures/forecast_compare.png\n"
373
+ ]
374
+ }
375
+ ],
376
+ "source": [
377
+ "\n",
378
+ "# Build monthly ts\n",
379
+ "start_year <- year(min(df_month2$month, na.rm = TRUE))\n",
380
+ "start_mon <- month(min(df_month2$month, na.rm = TRUE))\n",
381
+ "\n",
382
+ "y <- ts(df_month2$total_revenue, frequency = 12, start = c(start_year, start_mon))\n",
383
+ "\n",
384
+ "# holdout size: min(6, 20% of series), at least 1\n",
385
+ "h_test <- min(6, max(1, floor(length(y) / 5)))\n",
386
+ "train_ts <- head(y, length(y) - h_test)\n",
387
+ "test_ts <- tail(y, h_test)\n",
388
+ "\n",
389
+ "# Model A: ARIMA + Fourier\n",
390
+ "K <- 2\n",
391
+ "xreg_train <- fourier(train_ts, K = K)\n",
392
+ "fit_arima <- auto.arima(train_ts, xreg = xreg_train)\n",
393
+ "xreg_future <- fourier(train_ts, K = K, h = h_test)\n",
394
+ "fc_arima <- forecast(fit_arima, xreg = xreg_future, h = h_test)\n",
395
+ "\n",
396
+ "# Model B: ETS\n",
397
+ "fit_ets <- ets(train_ts)\n",
398
+ "fc_ets <- forecast(fit_ets, h = h_test)\n",
399
+ "\n",
400
+ "# Model C: Naive baseline\n",
401
+ "fc_naive <- naive(train_ts, h = h_test)\n",
402
+ "\n",
403
+ "# accuracy() tables\n",
404
+ "acc_arima <- as.data.frame(accuracy(fc_arima, test_ts))\n",
405
+ "acc_ets <- as.data.frame(accuracy(fc_ets, test_ts))\n",
406
+ "acc_naive <- as.data.frame(accuracy(fc_naive, test_ts))\n",
407
+ "\n",
408
+ "accuracy_tbl <- bind_rows(\n",
409
+ " acc_arima %>% mutate(model = \"ARIMA+Fourier\"),\n",
410
+ " acc_ets %>% mutate(model = \"ETS\"),\n",
411
+ " acc_naive %>% mutate(model = \"Naive\")\n",
412
+ ") %>% relocate(model)\n",
413
+ "\n",
414
+ "write_csv(accuracy_tbl, file.path(R_TAB_DIR, \"accuracy_table.csv\"))\n",
415
+ "cat(\"✅ Saved: artifacts/r/tables/accuracy_table.csv\\n\")\n",
416
+ "\n",
417
+ "# RMSE bar chart\n",
418
+ "p_rmse <- ggplot(accuracy_tbl, aes(x = reorder(model, RMSE), y = RMSE)) +\n",
419
+ " geom_col() +\n",
420
+ " coord_flip() +\n",
421
+ " labs(title = \"Forecast model comparison (RMSE on holdout)\", x = \"\", y = \"RMSE\") +\n",
422
+ " theme_minimal()\n",
423
+ "\n",
424
+ "ggsave(file.path(R_FIG_DIR, \"rmse_comparison.png\"), p_rmse, width = 8, height = 4, dpi = 160)\n",
425
+ "cat(\"✅ Saved: artifacts/r/figures/rmse_comparison.png\\n\")\n",
426
+ "\n",
427
+ "# Side-by-side forecast plots (simple, no extra deps)\n",
428
+ "png(file.path(R_FIG_DIR, \"forecast_compare.png\"), width = 1200, height = 500)\n",
429
+ "par(mfrow = c(1, 3))\n",
430
+ "plot(fc_arima, main = \"ARIMA + Fourier\", xlab = \"Time\", ylab = \"Total revenue\"); lines(test_ts, col = \"black\")\n",
431
+ "plot(fc_ets, main = \"ETS\", xlab = \"Time\", ylab = \"Total revenue\"); lines(test_ts, col = \"black\")\n",
432
+ "plot(fc_naive, main = \"Naive\", xlab = \"Time\", ylab = \"Total revenue\"); lines(test_ts, col = \"black\")\n",
433
+ "dev.off()\n",
434
+ "cat(\"✅ Saved: artifacts/r/figures/forecast_compare.png\\n\")"
435
+ ]
436
+ },
437
+ {
438
+ "cell_type": "markdown",
439
+ "id": "30bc017b",
440
+ "metadata": {
441
+ "id": "30bc017b"
442
+ },
443
+ "source": [
444
+ "## **5.** 💾 Some R metadata for Hugging Face"
445
+ ]
446
+ },
447
+ {
448
+ "cell_type": "code",
449
+ "execution_count": 7,
450
+ "id": "645cb12b",
451
+ "metadata": {
452
+ "colab": {
453
+ "base_uri": "https://localhost:8080/"
454
+ },
455
+ "id": "645cb12b",
456
+ "outputId": "d454e0a5-b986-45ca-9069-65a1c21ce540"
457
+ },
458
+ "outputs": [
459
+ {
460
+ "output_type": "stream",
461
+ "name": "stdout",
462
+ "text": [
463
+ "✅ Saved: artifacts/r/tables/r_meta.json\n",
464
+ "DONE. R artifacts written to: artifacts/r \n"
465
+ ]
466
+ }
467
+ ],
468
+ "source": [
469
+ "# =========================================================\n",
470
+ "# Metadata export (aligned with current notebook objects)\n",
471
+ "# =========================================================\n",
472
+ "\n",
473
+ "meta <- list(\n",
474
+ "\n",
475
+ " # ---------------------------\n",
476
+ " # Dataset footprint\n",
477
+ " # ---------------------------\n",
478
+ " n_titles = nrow(df_title),\n",
479
+ " n_months = nrow(df_month2),\n",
480
+ "\n",
481
+ " # ---------------------------\n",
482
+ " # Forecasting info\n",
483
+ " # (only if these objects exist in your forecasting section)\n",
484
+ " # ---------------------------\n",
485
+ " forecasting = list(\n",
486
+ " holdout_h = h_test,\n",
487
+ " arima_order = forecast::arimaorder(fit_arima),\n",
488
+ " ets_method = fit_ets$method\n",
489
+ " )\n",
490
+ ")\n",
491
+ "\n",
492
+ "jsonlite::write_json(\n",
493
+ " meta,\n",
494
+ " path = file.path(R_TAB_DIR, \"r_meta.json\"),\n",
495
+ " pretty = TRUE,\n",
496
+ " auto_unbox = TRUE\n",
497
+ ")\n",
498
+ "\n",
499
+ "cat(\"✅ Saved: artifacts/r/tables/r_meta.json\\n\")\n",
500
+ "cat(\"DONE. R artifacts written to:\", file.path(ART_DIR, \"r\"), \"\\n\")\n"
501
+ ]
502
+ }
503
+ ],
504
+ "metadata": {
505
+ "colab": {
506
+ "provenance": []
507
+ },
508
+ "kernelspec": {
509
+ "name": "ir",
510
+ "display_name": "R"
511
+ },
512
+ "language_info": {
513
+ "name": "R"
514
+ }
515
+ },
516
+ "nbformat": 4,
517
+ "nbformat_minor": 5
518
+ }