I have function like this:
myfun <- function ()
{
df <<- data.frame(a = 1)
}
myfun()
but it reports an error "Error in myfun() : cannot change value of locked binding for 'df'". I really need to modify the global variable df and I don't care if I mask existing function. How can I do this?
I discovered this solution. It works, but is there something less complicated?
myfun <- function ()
{
df <- data.frame(a = 1)
assign("df", df, envir = .GlobalEnv)
}
myfun()