How can I query the value of x for foo in the R code below?
make.foo <- function() {
x <- 123
function() x * 3
}
foo <- make.foo()
# now get foo's x
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A function will have an environment
from
?`function`so you can
getfrom that environment (or list the objects usingls)or if you want to know all the objects in the environment
and if you want to assign to that environment (ie change
x)You can even remove it from the environment
and then use a globally assigned
xand reassign to the
function‘s environment