The "context" you mean is I think the R global environment. Each instance of RenjinScriptEngine has its own, independent global environment.
You can inspect, modify, and clear the values set it in the global environment using R base functions, like so:
engine.eval("print(ls())"); // print all symbols in the global environment
engine.eval("rm(ls())"); // remove all symbols in the global environment
// (that don't start with a "." )
engine.eval("rm(ls(all.names=TRUE))"); // remove everything
You can also use the javax.script API to do the same:
engine.getBindings(ScriptContext.ENGINE).clear();
Depending on your use case, clearing the global environment may be sufficient, but keep in mind that a RenjinScriptEngine contains additional state.
If you load packages and/or their namespaces via library()
, require()
or mypackage::fun()
, that will affect the internal state of the RenjinScriptEngine.
Other things that affect the Session-level (RenjinScriptEngine) state:
- Global options set via
options()
- Random number generator state and seed
- Internal state of third-party packages
- Open files and other connections