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

tempvar

Gets a unique non-existing temporary variable name


Description

Gets a unique non-existing temporary variable name and optionally assigns it an initial value.

Usage

tempvar(prefix="var", value, envir=parent.frame(), inherits=FALSE)

Arguments

prefix

A character string specifying the prefix of the temporary variable name.

value

(optional) If given, a variable with the temporary name is assigned this value.

envir

An environment where the variable should exist.

inherits

A logical specifying whether the enclosing frames of the environment should be searched or not.

Value

Returns a character string.

Author(s)

Henrik Bengtsson

See Also

tempfile() and assign().

Examples

# Get a temporary variable
name <- tempvar()
print(name)

# Get and assign a temporary variable
name <- tempvar(value=base::letters)
print(name)
str(get(name))

# Get a temporary variable with custom prefix
name <- tempvar(prefix=".hidden")
print(name)

R.utils

Various Programming Utilities

v2.10.1
LGPL (>= 2.1)
Authors
Henrik Bengtsson [aut, cre, cph]
Initial release

We don't support your browser anymore

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