Learn R Programming

DIZutils (version 0.0.13)

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, `DIZutils::setenv2(key = var.name, val = var.value)` will create `testname = 7` in the system environment.

Usage

setenv2(key, val)

Arguments

key

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

val

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

Value

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

See Also

https://stackoverflow.com/a/12533155

Examples

Run this code
# NOT RUN {
  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")

  DIZutils::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