1 package org.rosuda.REngine;
2 // environments are like REXPReferences except that they cannot be resolved
4 /** REXPEnvironment represents an environment in R. Very much like {@link org.rosuda.REngine.REXPReference} this is a proxy object to the actual object on the R side. It provides methods for accessing the content of the environment. The actual implementation may vary by the back-end used and not all engines support environments. Check {@link org.rosuda.REngine.REngine.supportsEnvironments()} for the given engine. Environments are specific for a given engine, they cannot be passed across engines.
6 public class REXPEnvironment extends REXP {
7 /** engine associated with this environment */
9 /** transparent handle that can be used by the engine to indentify the environment. It is not used by REngine API itself. */
12 /** create a new environemnt reference - this constructor should never be used directly, use {@link REngine.newEnvironment()} instead.
13 * @param eng engine responsible for this environment
14 * @param handle handle used by the engine to identify this environment
16 public REXPEnvironment(REngine eng, Object handle) {
22 public boolean isEnvironment() { return true; }
24 /** returns the handle used to identify this environemnt in the engine - for internal use by engine implementations only
25 * @return handle of this environment */
26 public Object getHandle() { return handle; }
28 /** get a value from this environment
29 * @param name name of the value
30 * @param resolve if <code>false</code> returns a reference to the object, if <code>false</code> the reference is resolved
31 * @return value corresponding to the symbol name or possibly <code>null</code> if the value is unbound (the latter is currently engine-specific) */
32 public REXP get(String name, boolean resolve) throws REngineException {
34 return eng.get(name, this, resolve);
35 } catch (REXPMismatchException e) { // this should never happen because this is always guaranteed to be REXPEnv
36 throw(new REngineException(eng, "REXPMismatchException:"+e+" in get()"));
40 /** get a value from this environment - equavalent to <code>get(name, true)</code>.
41 * @param name name of the value
42 * @return value (see {@link #get(String,boolean)}) */
43 public REXP get(String name) throws REngineException {
44 return get(name, true);
47 /** assigns a value to a given symbol name
48 * @param name symbol name
49 * @param value value */
50 public void assign(String name, REXP value) throws REngineException, REXPMismatchException {
51 eng.assign(name, value, this);
54 /** returns the parent environment or a reference to it
55 * @param resolve if <code>true</code> returns the environemnt, otherwise a reference.
56 * @return parent environemnt (or a reference to it) */
57 public REXP parent(boolean resolve) throws REngineException {
59 return eng.getParentEnvironment(this, resolve);
60 } catch (REXPMismatchException e) { // this should never happen because this is always guaranteed to be REXPEnv
61 throw(new REngineException(eng, "REXPMismatchException:"+e+" in parent()"));
65 /** returns the parent environment. This is equivalent to <code>parent(true)</code>.
66 * @return parent environemnt */
67 public REXPEnvironment parent() throws REngineException {
68 return (REXPEnvironment) parent(true);