I want to use multiple objects created within a function with another function:
test1 <- function(x){
y <- x + 1
z <- x * 2
}
test2 <- function(...){
test1(x)
print(u <- y * z)
}
x <- 2
test2(test1)
It throws the error Error in print(u <- y * z) : object 'y' not found
.
How can I reuse all objects assigned in a function without using the global assignment <<-
?