65 Appendix A — Complete Environment Setup
66 Appendix A — Complete Environment Setup
This appendix provides comprehensive step-by-step instructions to set up a complete development environment for reproducing all analyses, code examples, and case studies in “AI-Powered Business Analytics.” The setup covers Windows, macOS, and Linux.
66.1 System Requirements
- Operating System: Windows 10+, macOS 10.15+, or Linux (Ubuntu 20.04+)
- Disk Space: 10 GB free
- RAM: 8 GB minimum (16 GB recommended for deep learning chapters)
- Internet: Required for package downloads
66.2 Part 1: R Installation
66.2.1 Windows
Download R from cran.r-project.org — select “Download R for Windows”
Click “base” and download the latest version (≥ 4.3.0)
Run the installer (e.g.,
R-4.3.2-win.exe)Choose default installation directory (usually
C:\Program Files\R\R-4.3.2)Complete the installation wizard
Verify installation by opening Command Prompt and typing:
R --version
66.2.2 macOS
Download R from cran.r-project.org — select “Download R for macOS”
Choose the appropriate version (Intel or Apple Silicon/M1/M2)
Download the
.pkgfile (version ≥ 4.3.0)Double-click the installer and follow the wizard
Verify installation in Terminal:
66.2.3 Linux (Ubuntu/Debian)
Open Terminal and add the CRAN repository:
Update and install:
Verify:
66.3 Part 2: RStudio Desktop Installation
RStudio is the recommended IDE for R development.
66.3.1 All Platforms
- Download from rstudio.com/products/rstudio/download
- Select RStudio Desktop (Free) — version ≥ 2024.04
- Choose your operating system and download the installer
- Run the installer and follow the wizard
- Launch RStudio and verify it detects R correctly
66.4 Part 3: Positron Installation (Optional Advanced IDE)
Positron is a modern polyglot IDE that supports R, Python, and Quarto seamlessly.
- Download from posit.co/download/positron
- Follow platform-specific instructions
- Launch Positron and configure default interpreter (R and Python paths)
66.5 Part 4: Quarto CLI Installation
Quarto is essential for rendering .qmd documents to HTML and PDF.
66.5.1 All Platforms (Recommended)
Download from quarto.org/docs/get-started
Choose your OS and download the installer (version ≥ 1.4)
Run the installer and follow the wizard
Verify in Terminal/Command Prompt:
66.5.2 Windows (Alternative: Chocolatey)
choco install quarto
66.5.3 macOS (Alternative: Homebrew)
66.5.4 Linux (Alternative: Direct download)
66.6 Part 5: Python Installation
66.6.1 Option A: Using pyenv (Recommended for Multi-Version Management)
macOS and Linux
Install pyenv:
Add to shell profile (
.bashrc,.zshrc):Reload shell:
Install Python 3.11:
Windows (Using pyenv-win)
Install via Chocolatey:
choco install pyenv-winInstall Python:
pyenv install 3.11.0 pyenv global 3.11.0
66.6.2 Option B: Using Conda (Recommended for Data Science)
Download Miniconda from conda.io/miniconda
Run the installer
Create a new environment:
66.6.3 Option C: Direct Installation
Download from python.org — version 3.11+
Run installer
Windows: Check “Add Python to PATH”
Verify:
66.7 Part 6: Setting Up a Python Virtual Environment
66.7.1 Using venv (Built-in)
66.7.2 Using Conda
66.8 Part 7: Installing R Packages
Open R or RStudio and install packages by chapter range. Use pak::pak() for faster parallel installation.
66.8.1 Installation Setup
66.8.2 Part I: Foundations (Chapters 1-11)
pak::pak(c(
# Data manipulation and tidyverse
"tidyverse",
"data.table",
"dtplyr",
# Statistical foundations
"stats",
"car",
"MASS",
"nortest",
# Hypothesis testing
"coin",
"exactRankTests",
# Machine learning basics
"caret",
"mlbench",
"rpart",
"rpart.plot",
# Visualisation
"ggplot2",
"plotly",
"igraph",
"ggraph",
"sf",
"leaflet",
# Time series
"forecast",
"tseries",
"xts",
"zoo"
))66.8.3 Part II: Advanced Methods (Chapters 12-25)
pak::pak(c(
# Text and NLP
"tm",
"tidytext",
"textdata",
"quanteda",
"topicmodels",
"sentiment",
"syuzhet",
# Image processing
"imager",
"magick",
# Recommendation engines
"recommenderlab",
"recosystem",
# Network analysis
"igraph",
"tidygraph",
"ggraph",
"statnet",
# Optimisation
"lpSolve",
"nloptr",
"optimx"
))66.8.4 Part III: Predictive Analytics (Chapters 26-36)
pak::pak(c(
# Advanced classification and regression
"randomForest",
"xgboost",
"lightgbm",
"glmnet",
"elasticnet",
"e1071",
"kernlab",
# Model evaluation
"pROC",
"ROCR",
"DescTools",
# Survival analysis
"survival",
"survminer",
"coxme",
# Clustering
"cluster",
"dbscan",
"mclust",
# SHAP and interpretability
"shapviz",
"iml"
))66.8.5 Part IV: Optimisation & Applications (Chapters 37-50)
66.9 Part 8: Installing Python Packages
Create a requirements.txt file in your project root:
# Data manipulation
pandas==2.0.3
numpy==1.24.3
polars==0.18.13
# Visualisation
matplotlib==3.7.2
seaborn==0.12.2
plotly==5.15.0
# Scikit-learn and classical ML
scikit-learn==1.3.0
xgboost==2.0.0
lightgbm==4.0.0
catboost==1.2.2
# Deep learning
tensorflow==2.13.0
torch==2.0.1
torchvision==0.15.2
# NLP and text
nltk==3.8.1
spacy==3.6.1
gensim==4.3.1
transformers==4.32.1
# Time series
statsmodels==0.14.0
prophet==1.1.5
# Network analysis
networkx==3.1
# Optimisation
scipy==1.11.2
pyomo==6.6.1
pulp==2.7.0
# Geospatial
geopandas==0.13.2
shapely==2.0.1
# Utilities
tqdm==4.66.1
joblib==1.3.1
pyyaml==6.0
# Jupyter notebooks (optional)
jupyter==1.0.0
jupyterlab==4.0.4
Install with:
66.9.1 Spacy Language Models (NLP)
After installing spacy, download language models:
66.10 Part 9: Configuring reticulate in R
To enable R to call Python, configure reticulate:
Add to your project’s .Rprofile (in project root):
66.11 Part 10: Setting Up a Quarto Book Project
Create a directory structure for a Quarto book:
# Create project directory
mkdir ai-business-analytics-book
cd ai-business-analytics-book
# Create subdirectories
mkdir chapters appendices data scripts
# Create Quarto configuration
cat > _quarto.yml << 'EOF'
project:
type: book
output-dir: _book
book:
title: "AI-Powered Business Analytics"
author: "Bongo Adi"
date: 2024-01-01
chapters:
- index.qmd
- chapters/01-introduction.qmd
# ... add remaining chapters
appendices:
- appendices/A-setup.qmd
# ... add remaining appendices
format:
html:
theme: cosmo
toc: true
toc-depth: 2
pdf:
documentclass: book
engine: lualatex
keep-tex: false
execute:
freeze: auto
EOF66.12 Part 11: LaTeX Installation (Required for PDF Rendering)
66.12.1 Windows
Download MiKTeX from miktex.org
Run the installer
Choose “Install missing packages on-the-fly”
Verify:
pdflatex --version
66.12.2 macOS
66.12.3 Linux (Ubuntu/Debian)
66.13 Part 12: Rendering Quarto Documents
66.13.1 Rendering to HTML
66.13.2 Rendering to PDF (LuaLaTeX)
In _quarto.yml:
Then:
66.13.3 Rendering Full Book
66.14 Part 13: Troubleshooting
66.14.1 Windows Issues
Problem: R command not found Solution: Add R to PATH. Go to Control Panel → System → Advanced → Environment Variables. Add C:\Program Files\R\R-x.x.x\bin to PATH.
Problem: LaTeX missing for PDF Solution: Install MiKTeX and ensure pdflatex is in PATH.
Problem: Python not found in reticulate Solution: In R, run reticulate::py_discover_config() to check Python locations, then explicitly set with use_virtualenv() or use_condaenv().
66.14.2 macOS Issues
Problem: Permission denied for Homebrew packages Solution:
Problem: M1/M2 compatibility Solution: Use native R build for macOS. Download from CRAN “for macOS 11+ (Apple Silicon)”.
66.14.3 Linux Issues
Problem: Build tools missing Solution: Install development headers:
Problem: Cannot load Python modules Solution: Ensure Python version matches reticulate expectations:
66.15 Part 14: Verification Script — “Hello, Data!”
66.15.1 R Verification Script
Save as verify_setup.R:
#!/usr/bin/env Rscript
cat("=== R Setup Verification ===\n\n")
# Check R version
cat("R Version:", as.character(getRVersion()), "\n")
if (getRVersion() < "4.3.0") {
cat("WARNING: R version should be >= 4.3.0\n")
}
# Check key packages
packages <- c(
"tidyverse", "data.table", "caret", "ggplot2",
"forecast", "xgboost", "keras", "reticulate"
)
cat("\nPackage Check:\n")
for (pkg in packages) {
if (requireNamespace(pkg, quietly = TRUE)) {
cat(" ✓", pkg, "\n")
} else {
cat(" ✗", pkg, "— MISSING\n")
}
}
# Check reticulate and Python
cat("\nPython Configuration:\n")
library(reticulate)
cat("Python:", py_config()$python, "\n")
cat("Version:", paste(py_config()$version, collapse = "."), "\n")
# Simple data manipulation test
cat("\nData Manipulation Test:\n")
library(tidyverse)
test_data <- tibble(
x = 1:10,
y = x^2
)
cat("Created test tibble with", nrow(test_data), "rows\n")
cat("\n✓ R setup verification complete!\n")Run with:
66.15.2 Python Verification Script
Save as verify_setup.py:
#!/usr/bin/env python
print("=== Python Setup Verification ===\n")
import sys
print(f"Python Version: {sys.version}")
required_packages = [
"pandas", "numpy", "matplotlib", "scikit-learn",
"tensorflow", "torch", "nltk", "statsmodels", "networkx"
]
print("\nPackage Check:")
for pkg in required_packages:
try:
__import__(pkg)
print(f" ✓ {pkg}")
except ImportError:
print(f" ✗ {pkg} — MISSING")
# Simple data test
print("\nData Manipulation Test:")
import pandas as pd
df = pd.DataFrame({
'x': range(1, 11),
'y': [i**2 for i in range(1, 11)]
})
print(f"Created DataFrame with {len(df)} rows")
print("\n✓ Python setup verification complete!")Run with:
66.16 Part 15: Quick Start Checklist
Once all items are checked, you are ready to reproduce all analyses in the book!
For issues or updates, visit the book’s GitHub repository.