x <- function(){
number<- 10
y <- function(){
number <- 20
}
y()
print(number)
}
x()
This code prints the value 10. How would I set the value of "number" within function "y ", so that it changes the value of "number" to 20 within function "x" and therefore prints the value 20, without assigning it to the global environment.
I tried to do this using the assign() function but I couldn't figure out what to set the parameter of "envir" to in order to achieve this e.g. assign("number", 20, envir = "whatever environment the of x is").