# Installation

The `topics` package relies on Java for high-performance processing. To ensure a smooth installation, please follow these two steps.

### Step 1: Install Java (Required)

Before installing the R package, you must have the Java Runtime Environment (JRE) installed on your computer. 1. Download Java from here or www.java.com/en/download/. 2. Restart your computer after installation to ensure R can detect the new system paths.

On Linux run: `sudo apt install libtirpc-dev libfreetype6-dev libpng-dev libtiff5-dev libjpeg-dev libharfbuzz-dev libfribidi-dev libgit2-dev libcairo2-dev`

### Step 2: Install topics in R

Open R or RStudio and run the following commands.

    # Install and verify the Java interface
    install.packages("topics")

You can also install the development version from GitHub.

    # Install devtools if not already present
    if (!requireNamespace("devtools", quietly = TRUE)) install.packages("devtools")

    # Install topics from GitHub
    devtools::install_github("theharmonylab/topics")

### Step 3: Memory Configuration

Topic modeling is memory-intensive. You must increase the Java memory limit before loading the library. If you skip this, you may encounter OutOfMemoryError during model training.

    # Set memory limit to 5GB (Run this BEFORE loading the library)
    options(java.parameters = "-Xmx5000m")
    library(topics)