Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

oneoffVariable

One-off Global Variables


Description

Defines a function that allow to get/assign a global variable whose value is ensured to be reset after each access.

Usage

oneoffVariable(default = NULL)

Arguments

default

default value to which the global variable is reset after each access. Default is NULL.

Value

a function with one argument (value) that provides get/set access to a global variable. If called with a value, it assigns this value to the global variable. If called with no argument, it returns the current value of the global variable and reset it to its default value – as defined at its creation.

Examples

x <- oneoffVariable(0)
# returns default value
x()
# assign a value
x(3)
# get the value
x()
# second call returns default value again 
x()

pkgmaker

Development Utilities for R Packages

v0.32.2
GPL (>= 2)
Authors
Renaud Gaujoux [aut, cre]
Initial release
2020-10-20

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.