Let's say I have the following function:
create_X <- function() {
x <- 14
}
Is there a way to give back the x variable to the console? So I can just hit x in my r console and then 14 pops up?
Let's say I have the following function:
create_X <- function() {
x <- 14
}
Is there a way to give back the x variable to the console? So I can just hit x in my r console and then 14 pops up?
Maybe this could help
create_X <- function() {
assign("x", 14, envir=globalenv())
}
create_X()
print(x)
#14
You could also carefully use
create_X <- function() {
x <<- 14
}
create_X()
print(x)
About this operator, see also How do you use "<<-" (scoping assignment) in R?