/** create a new factor REXP from an existing RFactor * @param factor factor object (can be of any index base, the contents will be pulled with base 1) */ public REXPFactor(RFactor factor) { super(factor.asIntegers(1)); this.factor = factor; this.levels = factor.levels(); attr = new REXPList( new RList( new REXP[] { new REXPString(this.levels), new REXPString("factor") }, new String[] { "levels", "class" })); }
/** retrieve an attribute of the given name from this object * @param name attribute name * @return attribute value or <code>null</code> if the attribute does not exist */ public REXP getAttribute(String name) { final REXPList a = _attr(); if (a==null || !a.isList()) return null; return a.asList().at(name); }
/** convenience method equivalent to <code>assign(symbol, new REXPString(d), null)</code> (see {@link #assign(String, REXP, REXP)}) @param symbol symbol name to assign to @param d value to assign */ public void assign(String symbol, String d) throws REngineException { try { assign(symbol, new REXPString(d), null); } catch (REXPMismatchException e) { throw(new REngineException(this, "REXPMismatchException in assign(,String[]): "+e)); } } /** convenience method equivalent to <code>assign(symbol, value, null)</code> (see {@link #assign(String, REXP, REXP)})
/** returns dimensions of the object (as determined by the "<code>dim</code>" attribute) * @return an array of integers with corresponding dimensions or <code>null</code> if the object has no dimension attribute */ public int[] dim() { try { return hasAttribute("dim")?_attr().asList().at("dim").asIntegers():null; } catch (REXPMismatchException me) { } return null; }
/** creates a new generic vector from a list. If the list is named, the <code>"names"</code> attribute is created automatically from it. * @param list list to create the vector from */ public REXPGenericVector(RList list) { super(); payload=(list==null)?new RList():list; // automatically generate 'names' attribute if (payload.isNamed()) attr = new REXPList( new RList(new REXP[] { new REXPString(payload.keys()) }, new String[] { "names" })); }
/** convenience method equivalent to <code>assign(symbol, new REXPInteger(d), null)</code> (see {@link #assign(String, REXP, REXP)}) @param symbol symbol name to assign to @param d values to assign */ public void assign(String symbol, int[] d) throws REngineException { try { assign(symbol, new REXPInteger(d), null); } catch (REXPMismatchException e) { throw(new REngineException(this, "REXPMismatchException in assign(,int[]): "+e)); } } /** convenience method equivalent to <code>assign(symbol, new REXPString(d), null)</code> (see {@link #assign(String, REXP, REXP)})
/** convenience method equivalent to <code>assign(symbol, new REXPDouble(d), null)</code> (see {@link #assign(String, REXP, REXP)}) @param symbol symbol name to assign to @param d values to assign */ public void assign(String symbol, double[] d) throws REngineException { try { assign(symbol, new REXPDouble(d), null); } catch (REXPMismatchException e) { throw(new REngineException(this, "REXPMismatchException in assign(,double[]): "+e)); } } /** convenience method equivalent to <code>assign(symbol, new REXPInteger(d), null)</code> (see {@link #assign(String, REXP, REXP)})
/** convenience method equivalent to <code>assign(symbol, new REXPRaw(d), null)</code> (see {@link #assign(String, REXP, REXP)}) @param symbol symbol name to assign to @param d values to assign */ public void assign(String symbol, byte[] d) throws REngineException { try { assign(symbol, new REXPRaw(d), null); } catch (REXPMismatchException e) { throw(new REngineException(this, "REXPMismatchException in assign(,byte[]): "+e)); } } /** convenience method equivalent to <code>assign(symbol, new REXPString(d), null)</code> (see {@link #assign(String, REXP, REXP)})
/** returns the parent environment or a reference to it * @param resolve if <code>true</code> returns the environemnt, otherwise a reference. * @return parent environemnt (or a reference to it) */ public REXP parent(boolean resolve) throws REngineException { try { return eng.getParentEnvironment(this, resolve); } catch (REXPMismatchException e) { // this should never happen because this is always guaranteed to be REXPEnv throw(new REngineException(eng, "REXPMismatchException:"+e+" in parent()")); } }
/** returns dimensions of the object (as determined by the "<code>dim</code>" attribute) * @return an array of integers with corresponding dimensions or <code>null</code> if the object has no dimension attribute */ public int[] dim() { try { return hasAttribute("dim")?_attr().asList().at("dim").asIntegers():null; } catch (REXPMismatchException me) { } return null; }
/** retrieve an attribute of the given name from this object * @param name attribute name * @return attribute value or <code>null</code> if the attribute does not exist */ public REXP getAttribute(String name) { final REXPList a = _attr(); if (a==null || !a.isList()) return null; return a.asList().at(name); }
/** creates a new generic vector from a list. If the list is named, the <code>"names"</code> attribute is created automatically from it. * @param list list to create the vector from */ public REXPGenericVector(RList list) { super(); payload=(list==null)?new RList():list; // automatically generate 'names' attribute if (payload.isNamed()) attr = new REXPList( new RList(new REXP[] { new REXPString(payload.keys()) }, new String[] { "names" })); }
/** create a new factor REXP from an existing RFactor * @param factor factor object (can be of any index base, the contents will be pulled with base 1) */ public REXPFactor(RFactor factor) { super(factor.asIntegers(1)); this.factor = factor; this.levels = factor.levels(); attr = new REXPList( new RList( new REXP[] { new REXPString(this.levels), new REXPString("factor") }, new String[] { "levels", "class" })); }
/** convenience method equivalent to <code>assign(symbol, new REXPString(d), null)</code> (see {@link #assign(String, REXP, REXP)}) @param symbol symbol name to assign to @param d values to assign */ public void assign(String symbol, String[] d) throws REngineException { try { assign(symbol, new REXPString(d), null); } catch (REXPMismatchException e) { throw(new REngineException(this, "REXPMismatchException in assign(,String[]): "+e)); } } /** convenience method equivalent to <code>assign(symbol, new REXPRaw(d), null)</code> (see {@link #assign(String, REXP, REXP)})
/** convenience method equivalent to <code>assign(symbol, new REXPInteger(d), null)</code> (see {@link #assign(String, REXP, REXP)}) @param symbol symbol name to assign to @param d values to assign */ public void assign(String symbol, int[] d) throws REngineException { try { assign(symbol, new REXPInteger(d), null); } catch (REXPMismatchException e) { throw(new REngineException(this, "REXPMismatchException in assign(,int[]): "+e)); } } /** convenience method equivalent to <code>assign(symbol, new REXPString(d), null)</code> (see {@link #assign(String, REXP, REXP)})
/** convenience method equivalent to <code>assign(symbol, new REXPDouble(d), null)</code> (see {@link #assign(String, REXP, REXP)}) @param symbol symbol name to assign to @param d values to assign */ public void assign(String symbol, double[] d) throws REngineException { try { assign(symbol, new REXPDouble(d), null); } catch (REXPMismatchException e) { throw(new REngineException(this, "REXPMismatchException in assign(,double[]): "+e)); } } /** convenience method equivalent to <code>assign(symbol, new REXPInteger(d), null)</code> (see {@link #assign(String, REXP, REXP)})
/** convenience method equivalent to <code>assign(symbol, new REXPRaw(d), null)</code> (see {@link #assign(String, REXP, REXP)}) @param symbol symbol name to assign to @param d values to assign */ public void assign(String symbol, byte[] d) throws REngineException { try { assign(symbol, new REXPRaw(d), null); } catch (REXPMismatchException e) { throw(new REngineException(this, "REXPMismatchException in assign(,byte[]): "+e)); } } /** convenience method equivalent to <code>assign(symbol, new REXPString(d), null)</code> (see {@link #assign(String, REXP, REXP)})
/** checks whether this obejct has a given attribute * @param name attribute name * @return <code>true</code> if the attribute exists, <code>false</code> otherwise */ public boolean hasAttribute(String name) { final REXPList a = _attr(); return (a!=null && a.isList() && a.asList().at(name)!=null); }
/** convenience method equivalent to <code>assign(symbol, new REXPString(d), null)</code> (see {@link #assign(String, REXP, REXP)}) @param symbol symbol name to assign to @param d values to assign */ public void assign(String symbol, String[] d) throws REngineException { try { assign(symbol, new REXPString(d), null); } catch (REXPMismatchException e) { throw(new REngineException(this, "REXPMismatchException in assign(,String[]): "+e)); } } /** convenience method equivalent to <code>assign(symbol, new REXPRaw(d), null)</code> (see {@link #assign(String, REXP, REXP)})
/** checks whether this obejct has a given attribute * @param name attribute name * @return <code>true</code> if the attribute exists, <code>false</code> otherwise */ public boolean hasAttribute(String name) { final REXPList a = _attr(); return (a!=null && a.isList() && a.asList().at(name)!=null); }