setenv2 {DIZtools}R Documentation

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)

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

  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] ""


[Package DIZtools version 1.0.1 Index]