Question

I have a file with an R program. I load it interactively on R and then I call the main function. During the execution I fill up some global lists but when I run the main function again I want those lists to be empty. How can I empty a filled up list? I tried doing

list <- NULL

after execution but it didn't work.

Was it helpful?

Solution

Since you are setting them globally, you probably need list <<- NULL, because the <<- operator assigns global variables.

Edit, per @Dason's comment:

The <<- operator can in some circumstances fail to change the value of a variable in all possible environments. For that reason, it is better to use

assign("list", NULL, envir = .GlobalEnv)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top