The assign()
function in R is simply used to assign a value to a name in an environment.
assign(x, value, pos = -1, envir = as.environment(pos),
inherits = FALSE, immediate = TRUE)
The assign()
function takes the following mandatory parameter values:
x
: This represents the variable name that is given as a character string.value
: This is the value to be assigned to the x
variable.The assign()
function takes the following optional parameter values:
pos
: This represents where to do the assignment. By default, it is done in the current environment.envir
: This represents the environment.inherits
: This is used in case the enclosing frames of the environment need to be inspected or not.immediate
: This is an ignored compatibility feature.# using the assign() functionassign('x', 'Theo')x# using the assign() functionassign(x, 42)Theo
assign()
function to assign the value "Theo"
to the variable name x
.assign()
function to assign the value 42
to the variable x
, which is already the same as Theo
in the environment.Theo
.