---
title: "RequireR"
author: "Peter van den Berg"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{RequireR}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
source("../R/requireR.R")
```
The requireR package can be used to modularize your code. Using requireR, your system components can be separated and combined easier. The requireR packages is inspired by the JavaScript library 'RequireJS'<http://requirejs.org/>. 

Files will become **selfcontained**. Modules can contain private variables and functions, and only communicate via their interface variables.

The global environment can stay **clean**. (almost) no variables end up in the global environment, so no more name collisions or related problems.

Depedencies are always **explicified**. Each file contains all its dependencies, so you directly see where the file is dependent on.

A typical use case is the following:

```{r}
#hello.R
requireR(function() {
  "hello"
})
```

```{r}
#world.R
requireR(function() {
  "world"
})
```

```{r}
requireR(
  "hello.R",
  "world.R",
  function(hello, world) {
    paste(hello, world)
})
```

As you can see, all code is wrapped within the requireR function. The variables 'hello' and 'world' can only be used within the wrapped function, and do not end up in the global scope.

You can also use requireR within your module-less code (although this is not recommended)
```{r}
hello <- requireR("hello.R")
world <- requireR("world.R")
paste(hello, world)
```
