Learn R Programming

DIZtools (version 1.0.3)

setenv2: Assign variables to the system environment.

Description

Create a system environment variable with the use of variables. While `var.name = "testname"; var.value = 7` and `Sys.setenv(var.name = var.value)` will create `var.name = 7` in the system environment, `DIZtools::setenv2(key = var.name, val = var.value)` will create `testname = 7` in the system environment.

Usage

setenv2(key, val)

Value

No return value, called for side effects (see description).

Arguments

key

A character (!) string. The name of the assigned variable

val

An object. The object that will be assigned to 'key'.

See Also

Examples

Run this code
  var.name = "testname"
  var.value = 7

  Sys.setenv(var.name = var.value)

  Sys.getenv("testname")
  #> [1] ""
  Sys.getenv("var.name")
  #> [1] "7"

  Sys.unsetenv("var.name")
  Sys.unsetenv("testname")

  setenv2(key = var.name, val = var.value)
  Sys.getenv("testname")
  #> [1] "7"
  Sys.getenv("var.name")
  #> [1] ""

Run the code above in your browser using DataLab