---
title: "Installation"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Installation}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

# 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](https://www.oracle.com/java/technologies/downloads/) or www.java.com/en/download/.
2. Restart your computer after installation to ensure R can detect the new system paths.

### Step 2: Install topics in R
Open R or RStudio and run the following commands.

```r
# Install and verify the Java interface
install.packages("topics")
```
You can also install the development version from GitHub.

```r

# 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)
```
