knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
The mod
package provides a simple and friendly way to structure program and data into flexible and independent units for programming and interactive use. Modules indtroduced by the mod
package offer merits and conveniences currently absent from R.
Programs need to be oraganized into units.
A package is a very robust solution, but is formal and compliated; packages require additional knowledge to R and must be installed in the local library by install.packages()
; it is not easy to manage different versions of the same package. On the other hand, simple R scripts, often executed by source()
, are brittle and may create namespace conflict; They are unsuitable for building tools and applications.
Modules fills the hollow middleground by allowing programs to live separately and work together at the same time. Each module has its own scope, host is own objects, an can each use different packages without interefering with each other or the user's global search path. They can be created either inline along other programs or from a standalone file, and can be used in the user's working environment, as a part of a package, or in other modules.
Install the published version from CRAN with:
install.packages("mod")
Install the development version from GitHub with:
devtools::install_github("iqis/mod")
The mod
package has a simple UI:
module()
/mod::ule()
From a file: source_module()
The search path:
use()
Detach a module: drop()
Inside a module:
provide()
require()
refer()
name()
my_numbers <- mod::ule({ numbers <- c(1,2,2,2,3,3,4,5,6) }) my_plot <- mod::ule({ refer(my_numbers) numbers_plot <- function(x = numbers) { plot(x, col = "purple", pch = 15) title("Numbers", ylab = "Value") } }) my_numbers$numbers my_plot$numbers_plot()
mod
website
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.