This project demonstrates how to train a model in R and log metrics to Weights & Biases using a Python bridge.
src/R/models/LinearModelTrainer.R: R6 class for model training.src/R/utils/WandbLogger.R: R6 class that handles communication with Python.src/python/wandb_adapter.py: Python script that interfaces with the W&B SDK.main.R: Main entry point.
Run the install script:
Rscript install.RYou need wandb installed.
pip install -r requirements.txt- Copy
.Renviron.exampleto.Renviron:cp .Renviron.example .Renviron
- Edit
.Renvironand add your W&B API Key:Or ensure you are logged in via CLI:WANDB_API_KEY=your_actual_api_keywandb login
Run the main R script:
Rscript main.ROr source main.R in your RStudio session and run main().
- R trains the model and calculates metrics.
WandbLoggerin R writes these metrics to a temporary JSON file.- R calls
src/python/wandb_adapter.pyviasystem2(). - The Python script reads the JSON, logs to W&B, and exits.