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.

有帮助吗?

解决方案

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)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top