I created the following function:
math_funct <- function(a ,b){
c <<- a+b
print(c)
d <<- a-b
print(d)
e = c*d
print(e)
}
And when i call it with input parameters 10 and 20, I get the following error about variable 'c':
math_funct(a=10, b=20)
Error in math_funct(a = 10, b = 20) :
cannot change value of locked binding for 'c'
However, when i run the very same function replacing 'c' with arbitrarily selected variable name of 'k', it runs just fine.
math_funct <- function(a ,b){
k <<- a+b
print(k)
d <<- a-b
print(d)
e = k*d
print(e)
}
math_funct(a=10, b=20)
[1] 30
[1] -10
[1] -300