# ============================================================
# --- R packages ---
pkgs <- c(
# Text analysis
"quanteda",
"quanteda.textmodels",
"quanteda.textplots",
"quanteda.textstats",
"LSX",
"rollama",
# Data wrangling & visualisation
"tidyverse",
"ggplot2",
"scales",
"ggrepel",
"viridis",
"corrplot",
"kableExtra",
# Classification metrics (Module 4)
"yardstick",
# HTTP / API calls (for OLLAMA)
"httr2",
"jsonlite",
"glue",
# Python bridge (for BERT models)
"reticulate",
"corrplot"
)
install.packages(pkgs, repos = "https://cloud.r-project.org")
# --- Python environment (for BERT modules) ---
library(reticulate)
# Create a dedicated virtual environment
virtualenv_create("r-reticulate")
use_virtualenv("r-reticulate", required = TRUE)
# Install Python packages
py_install(
c("pandas", "openpyxl", "transformers", "torch", "numpy", "scipy", "seaborn", "matplotlib", "python-docx", "nltk"),
envname = "r-reticulate",
pip = TRUE
)2 Prerequisites
Supervised and Unsupervised Text Scaling
2.1 Install OLLAMA
— OLLAMA (Module 4) — To run the code, you must install OLLAMA separately: https://ollama.com/download
2.2 Install R packages
— R packages (all modules) — The code in the lecture relies on a number of R packages. The code also sets up a Python installation through reticulate (this will be used for BERT models). You can install them all at once with the following code: