Activity: function scoping

Instructions:

What will happen?

For each question, predict what will happen when the code is run. Then run the code and check whether your prediction was correct.

x <- 10

g02 <- function(x){
  x <- x + 1
  return(x)
}

g02(x)
x + 1
x <- 10

g02 <- function(x){
  x <- x + 1
  return(x)
}

x <- g02(x)
x + 1
g02 <- function(y){
  y <- y - 1
  return(y)
}

g02(g02(20))