builder

builder is a pre-processor for R that brings C-like preprocessor capabilities to R development. It enables directives, macros, conditional compilation, f-strings, and more—all processed at build time with zero runtime overhead. Currently only works on POSIX systems.

Installation

Install builder with a single command:

curl -fsSL https://builder.opifex.org/install.sh | sh

Features

Usage

Builder reads R files from the srcr directory and writes processed files to the R directory:

builder -input srcr -output R

Pass definitions at build time with -D flags:

builder -input srcr -output R -DDEBUG -DVERSION 3

Example

Define constants and use conditional compilation:

#define DEBUG TRUE
#define VERSION 2

#ifdef DEBUG
cat("Debug mode enabled\n")
#endif

#if VERSION > 1
cat("Using new API\n")
#else
cat("Using legacy API\n")
#endif

Create reusable macros with parameters:

#define
LOG(level, msg){
  cat("[", level, "] ", msg, "\n", sep = "")
}
#enddef

LOG("INFO", "Application started")
LOG("ERROR", "Something went wrong")

Expands to:

cat("[", "INFO", "] ", "Application started", "\n", sep = "")
cat("[", "ERROR", "] ", "Something went wrong", "\n", sep = "")

View the source code on GitHub.