Question



Passing variables between functions

Dr. Ballings,

I'm having trouble passing the newest day from the model building function over to the predict function and keeping it static, without
having it in the global environment.

Which if I understand correctly we are not allowed to have anything in the global environment other than the 2 functions correct?

Could you please give an example of how to pass a variable from one function to another, then being able to rerun that second function and
having it maintain the static variable?

Thanks,
Michael





Answers and follow-up questions





Answer or follow-up question 1

Dear Michael,

"Which if I understand correctly we are not allowed to have anything in the global environment other than the 2 functions correct? "

Correct.

"Could you please give an example of how to pass a variable from one function to another, then being able to rerun that second function and
having it maintain the static variable? "

Sure, here is an example:


foo <- function(){
"hello"
}

bar <- function(a){
paste(a,"world")
}

var1 <- foo()
bar(var1)




Sign in to be able to add an answer or mark this question as resolved.