export: Export mechanism for modules

Description Usage Arguments Details Examples

View source: R/export.R

Description

You can declare exports very much like the export mechanism in R packages: you define which objects from the module you make available to a user. All other objects are kept private, local, to the module.

Usage

1
export(..., where = parent.frame())

Arguments

...

(character, or unquoted expression) names to export from module. A character of length 1 with a leading "^" is interpreted as regular expression. Arguments can be named and used for renaming exports.

where

(environment) typically the calling environment. Should only be relevant for testing.

Details

A module can have several export declarations, e.g. directly in front of each function definition. That means: exports stack up. When you supply a regular expression, however, only one export pattern should be declared. A regular expression is denoted, as a convention, as character vector of length one with a leading "^".

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
module({
  export("foo")
  foo <- function() "foo"
  bar <- function() "bar"
})

module({
  export("foo")
  foo <- function() "foo"
  export("bar")
  bar <- function() "bar"
})

module({
  export("foo", "bar")
  foo <- function() "foo"
  bar <- function() "bar"
})

module({
  export("^f.*$")
  foo <- function() "foo"
  bar <- function() "bar"
})

module({
  export(bar = foo)
  foo <- function() "foo"
})

modules documentation built on Feb. 7, 2021, 1:06 a.m.