You could use a closure to obtain similar results without the risks associated with risks alluded to above. Without knowing exactly what you're trying to do, it's difficult to present a relevant example. But the below code might be of interest...
create.functions <- function(x){
list(
function() x,
function() x+1,
function() x^2
)
}
x <- 0
f1 <- create.functions(5)
f1[[1]]()
[1] 5
f1[[2]]()
[1] 6
f1[[3]]()
[1] 25
f2 <- create.functions(3)
f2[[1]]()
[1] 3
f2[[2]]()
[1] 4
f2[[3]]()
[1] 9
x
[1] 0
Notice that you can create a suite of functions sharing the same parameter, x, without any conflict between the parameter x and the value of x in the global environment. If you need a new set of functions where the parameter of x is differently defined, you can just create a new set.
This could even be worked such that code relying on the suite of functions need not be edited when changing the value of your parameter:
f <- create.functions(5)
f[[1]]()/f[[3]]()
[1] 0.2
f <- create.functions(3)
f[[1]]()/f[[3]]()
[1] 0.3333333
Note that the same line of code f[[1]]()/f[[3]]()
, returns different results depending on how your parameter x has been defined.