• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java SEXP类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.renjin.sexp.SEXP的典型用法代码示例。如果您正苦于以下问题:Java SEXP类的具体用法?Java SEXP怎么用?Java SEXP使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SEXP类属于org.renjin.sexp包,在下文中一共展示了SEXP类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: doApply

import org.renjin.sexp.SEXP; //导入依赖的package包/类
public static SEXP doApply(Context context, Environment environment, SEXP arg0, SEXP arg1)
    throws Exception
{
    if ((arg0 instanceof ListVector)&&((arg1 instanceof Vector)&&StringVector.VECTOR_TYPE.isWiderThanOrEqualTo(((Vector) arg1)))) {
        return Time.asPOSIXct(((ListVector) arg0), WrapperRuntime.convertToString(arg1));
    } else {
        throw new EvalException(String.format("Invalid argument:\n\tas.POSIXct(%s, %s)\n\tExpected:\n\tas.POSIXct(list, character(1))", arg0 .getTypeName(), arg1 .getTypeName()));
    }
}
 
开发者ID:bedatadriven,项目名称:renjin-statet,代码行数:10,代码来源:R$primitive$as$POSIXct.java


示例2: add

import org.renjin.sexp.SEXP; //导入依赖的package包/类
@Override
public Builder add(SEXP in) {
	if((in instanceof StringVector)) {
		StringVector value = (StringVector)in;			
		String str = value.getElementAsString(0);
		
		int index = levels.indexOf(str);
		if(index == -1) {
			index = levels.size();
			levels.add(str);				
		}
		
		// R indexes start at 1 not 0
		delegate.add(index + 1);			
		return this;
	} else {
		return null;
	}
}
 
开发者ID:james-jw,项目名称:xq-renjin,代码行数:20,代码来源:XqRenjinFactorBuilder.java


示例3: invValue

import org.renjin.sexp.SEXP; //导入依赖的package包/类
@Override
public Value invValue(QueryContext qc, InputInfo ii, Value... args) throws QueryException {
	RenjinScriptEngine  engine = (RenjinScriptEngine) renjin.getEngine();
	Context ctx = engine.getTopLevelContext();
	
	PairList.Builder arguments = new PairList.Builder();
	for(Value v : args) {
		if(v.size() > 0) {
			arguments.add(XqRenjinModule.xQueryValueToRValue(renjin, v));
		}
	}
	
	FunctionCall call = new FunctionCall(func, arguments.build());	
	SEXP result = ctx.evaluate(call);
	
	return XqRenjinModule.rValueToXQueryValue(renjin, result);
}
 
开发者ID:james-jw,项目名称:xq-renjin,代码行数:18,代码来源:XqRenjinFunction.java


示例4: rValueToXQueryValue

import org.renjin.sexp.SEXP; //导入依赖的package包/类
/**
   * Converts an R value (SEXP) into a XQuery value (Value)
   * 
   * @param renjin Engine the value exists in.
   * @param in The value to convert
   * @return The converted value for use in XQuery
   */
public static Value rValueToXQueryValue(XqRenjin renjin, SEXP in) {
	Value out = empty.value();
	
	if(in != null) {
		if (in instanceof ListVector) {
			out = processListVectorValue(renjin, (ListVector) in);
		} else if (in instanceof AtomicVector) {
			out = processAtomicVectorValue(renjin, (AtomicVector) in);
		} else if (in instanceof Function) {
			out = processFunctionValue(renjin, (Function) in);
		} else if (in instanceof FunctionCall) {
			out = processFunctionCallValue(renjin, (FunctionCall) in);
		}
	}
	
	return out;
}
 
开发者ID:james-jw,项目名称:xq-renjin,代码行数:25,代码来源:XqRenjinModule.java


示例5: testLocals

import org.renjin.sexp.SEXP; //导入依赖的package包/类
@Test
public void testLocals() throws ScriptException {
	final Context context = new Context(ScriptService.class);
	final ScriptService scriptService = context.getService(ScriptService.class);

	final ScriptLanguage language = scriptService.getLanguageByExtension("r");
	final ScriptEngine engine = language.getScriptEngine();
	assertEquals(RenjinScriptEngine.class, engine.getClass());
	engine.put("hello", 17);
	assertEquals(17, RenjinUtils.getJavaValue((SEXP) engine.eval("hello")));
	assertEquals(17, RenjinUtils.getJavaValue((SEXP) engine.get("hello")));

	final Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
	bindings.clear();
	assertNull(RenjinUtils.getJavaValue((SEXP) engine.get("hello")));
	assertNull(RenjinUtils.getJavaValue((SEXP) engine.get("polar_kraken")));
}
 
开发者ID:scijava,项目名称:scripting-renjin,代码行数:18,代码来源:RenjinTest.java


示例6: parseAll

import org.renjin.sexp.SEXP; //导入依赖的package包/类
private ExpressionVector parseAll() throws IOException {
  List<SEXP> exprList = new ArrayList();

  while (parse()) {
    StatusResult status = getResultStatus();
    switch (status) {
      case EMPTY:
        break;
      case INCOMPLETE:
      case OK:
        exprList.add(getResult());
        break;
      case ERROR:
        throw new ParseException(getResultStatus().toString());
      case EOF:
        return new ExpressionVector( exprList );
    }
  }
  return new ExpressionVector( exprList );
}
 
开发者ID:bedatadriven,项目名称:renjin-statet,代码行数:21,代码来源:RParser.java


示例7: doApply

import org.renjin.sexp.SEXP; //导入依赖的package包/类
public static SEXP doApply(Context context, Environment environment, SEXP arg0, SEXP arg1, SEXP arg2, SEXP arg3)
    throws Exception
{
    if (((((arg0 instanceof Vector)&&StringVector.VECTOR_TYPE.isWiderThanOrEqualTo(((Vector) arg0)))&&(arg1 instanceof SEXP))&&(arg2 instanceof SEXP))&&(arg3 instanceof SEXP)) {
        return Native.dynLoad(WrapperRuntime.convertToString(arg0), ((SEXP) arg1), ((SEXP) arg2), ((SEXP) arg3));
    } else {
        throw new EvalException(String.format("Invalid argument:\n\tdyn.load(%s, %s, %s, %s)\n\tExpected:\n\tdyn.load(character(1), any, any, any)", arg0 .getTypeName(), arg1 .getTypeName(), arg2 .getTypeName(), arg3 .getTypeName()));
    }
}
 
开发者ID:bedatadriven,项目名称:renjin-statet,代码行数:10,代码来源:R$primitive$dyn$load.java


示例8: asFunctionDefault

import org.renjin.sexp.SEXP; //导入依赖的package包/类
/**
 * Default implementation of as.function. Note that this is an
 * internal primitive called by the closure "as.function.default" in the
 * base package, so it is not itself generic.
 * 
 * @param list a ListVector containing the formal argument and the last element as the function body
 * @param envir the environment overwhich to close
 * @return a new Closure
 */
@Primitive("as.function.default")
public static Closure asFunctionDefault(ListVector list, Environment envir) {

  PairList.Builder formals = new PairList.Builder();
  for(int i=0;(i+1)<list.length();++i) {
    String name = list.getName(i);
    if(Strings.isNullOrEmpty(name)) {
      throw new EvalException("formal arguments to a closure must be named");
    }
    formals.add(name, list.getElementAsSEXP(i));
  }
  SEXP body = list.getElementAsSEXP(list.length() - 1);
  
  return new Closure(envir, formals.build(), body);
}
 
开发者ID:bedatadriven,项目名称:renjin-statet,代码行数:25,代码来源:Types.java


示例9: getDouble

import org.renjin.sexp.SEXP; //导入依赖的package包/类
@Override
public double getDouble(final String variable) {
    try {
        final SEXP sexp = (SEXP) engine.unwrap().eval(variable);
        return sexp.asReal();
    } catch (final ScriptException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:subes,项目名称:invesdwin-context-r,代码行数:10,代码来源:RenjinScriptTaskResultsR.java


示例10: getBoolean

import org.renjin.sexp.SEXP; //导入依赖的package包/类
@Override
public boolean getBoolean(final String variable) {
    try {
        final SEXP sexp = (SEXP) engine.unwrap().eval(variable);
        return sexp.asLogical() == Logical.TRUE;
    } catch (final ScriptException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:subes,项目名称:invesdwin-context-r,代码行数:10,代码来源:RenjinScriptTaskResultsR.java


示例11: invValue

import org.renjin.sexp.SEXP; //导入依赖的package包/类
@Override
public Value invValue(QueryContext qc, InputInfo ii, Value... args) throws QueryException {
       Value name = args[0];
       SEXP rValue = null;
       int index = vector.getIndexByName((String) name.toJava());
       if(index >= 0) {
       	rValue = vector.getElementAsSEXP(index);
       } else {
       	AttributeMap attrs = vector.getAttributes();
       	if(!(vector instanceof ListVector)) {
       		Vector rows = attrs.getDimNames().getElementAsSEXP(0);
       		Vector columns = attrs.getDimNames().getElementAsSEXP(1);
       		int binSize = vector.length() / columns.length();
       		int colIndex = columns.indexOf(new StringArrayVector(((String)name.toJava())), 0, 0);
       		if(colIndex >= 0) {
       			Builder builder = XqRenjinModule.vectorToBuilder(vector, binSize);
       			for(int i = colIndex * binSize, x = 0; x < binSize; x++, i++) {
       				builder.add(vector.getElementAsSEXP(i));
       			}
       			rValue = builder.build();
       		}
       	} else {
       		rValue = attrs.get((String) name.toJava());
       	}
       }

   	return rValue.length() == 0 ? (new ValueBuilder()).value() : XqRenjinModule.rValueToXQueryValue(renjin, rValue);
}
 
开发者ID:james-jw,项目名称:xq-renjin,代码行数:29,代码来源:XqRenjinObject.java


示例12: xQueryValueToRValue

import org.renjin.sexp.SEXP; //导入依赖的package包/类
/**
    * Converts an XQuery value (Value) into an R value (SEXP)
    * 
    * @param renjin Engine the value exists in.
    * @param in The value to convert
    * @return The converted value for use in R
    */
   public static SEXP xQueryValueToRValue(XqRenjin renjin, Value val) throws QueryException {
	// TODO Auto-generated method stub
   	SEXP out = null;
   	
   	if(val instanceof XqRenjinObject) {
   		out = ((XqRenjinObject)val).getVector();
   	} else if(val instanceof Map) {
   		out = processXQueryMap(renjin, (Map)val);
   	} else if(val.size() > 1 && val instanceof Seq && val.itemAt(0) instanceof Map) {
   		out = processXQueryAsDataFrame(renjin, val);
   	} 
   	
   	if(out == null && (val instanceof Array || val instanceof Seq)) {
   		out = processXQueryArray(renjin, val);
   	} else if(out == null && val instanceof FItem) {
   		out = processXQueryFunction(renjin, (FItem)val);
   	}
   	
   	if(out == null) {    		
   		try {
   			Object jValue = val.toJava();
   			if(jValue instanceof BigInteger) {
   				jValue = ((BigInteger)jValue).intValue();
   			}
   			
			out = RuntimeConverter.INSTANCE.convertToR(jValue);
		} catch (QueryException e) {
			throw new QueryException("Failed to convert value to R value: " + val.toString());
		}
   	}
   	
	return out;
}
 
开发者ID:james-jw,项目名称:xq-renjin,代码行数:41,代码来源:XqRenjinModule.java


示例13: processXQueryArray

import org.renjin.sexp.SEXP; //导入依赖的package包/类
private static SEXP processXQueryArray(XqRenjin renjin, Value val) throws QueryException {
	SEXP out = null;
	boolean isArray = false;
	if(val instanceof Array) {
		isArray = true;
		if(((Array)val).get(0) instanceof Map) {
			out = processXQueryAsDataFrame(renjin, val);
		}
	}

	Builder builder = xqValueToBuilder(val);
	if(out == null) {
		long size = isArray ? ((Array)val).arraySize() : val.size();
		for(long i = 0; i < size; i++) {
		    Item item = (Item) (isArray ? ((Array)val).get(i) : val.itemAt(i));
			try {
				builder.add(XqRenjinModule.xQueryValueToRValue(renjin, item));
			} catch (QueryException e) {
				throw new QueryException("Failed to process array value: " + item.toString() + ". " + e.getMessage());
			}
		}
		
		out = builder.build();
	}
	
	return out;
}
 
开发者ID:james-jw,项目名称:xq-renjin,代码行数:28,代码来源:XqRenjinModule.java


示例14: processXQueryMap

import org.renjin.sexp.SEXP; //导入依赖的package包/类
private static SEXP processXQueryMap(XqRenjin renjin, Map val) throws QueryException {
	Value keys = val.keys();
	NamedBuilder out = ListVector.newNamedBuilder();
	for(Item key : keys) {
		out.add((String)key.toJava(), xQueryValueToRValue(renjin, val.get(key, null)));
	}
	
	return out.build();
}
 
开发者ID:james-jw,项目名称:xq-renjin,代码行数:10,代码来源:XqRenjinModule.java


示例15: prePassCode

import org.renjin.sexp.SEXP; //导入依赖的package包/类
/**
 * Evaluate all the function calls.
 */
public void prePassCode() {
  SEXP source = RParser.parseSource(this.programText + "\n", "inline-string");
  if (isSameClass(source, ExpressionVector.class)) {
    ExpressionVector ev = (ExpressionVector) source;
    // Stores the expressions except size().
    List<SEXP> sexps = new ArrayList<SEXP>();
    for (int i = ev.length() - 1; i >= 0; --i) {
      if (isSameClass(ev.get(i), FunctionCall.class)
          && isSameClass(((FunctionCall) ev.get(i)).getFunction(), Symbol.class)) {
        if (((Symbol) ((FunctionCall) ev.get(i)).getFunction()).getPrintName().equals("<-")) {
          this.renjinEngine.getTopLevelContext().evaluate(ev.get(i),
              this.renjinEngine.getTopLevelContext().getEnvironment());
          sexps.add(ev.get(i));
        } else if (((Symbol) ((FunctionCall) ev.get(i)).getFunction()).getPrintName()
            .equals(Constant.SIZE_NAME)) {
          // size function is defined in global namespace.
          log("size function is defined in global namespace.");
          hasSize = true;
          sizeFunction = ev.get(i);
        } else {
          sexps.add(ev.get(i));
        }
      }
    }

    expressionVector = new ExpressionVector(sexps);
  }
}
 
开发者ID:gaocegege,项目名称:Processing.R,代码行数:32,代码来源:RLangPApplet.java


示例16: getJavaValue

import org.renjin.sexp.SEXP; //导入依赖的package包/类
/**
 * Extracts a value from the specified R variable.
 *
 * @param value The R value to decode.
 */
public static Object getJavaValue(final SEXP value) {
	if (value == null || value == org.renjin.sexp.Symbol.UNBOUND_VALUE)
		return null;

	try {
		// R has no concept of scalars, so if we have a length 1 int or
		// double array we should unwrap it

		// TODO consider using unsafe returns instead - they return the
		// underlying array by reference
		if (value instanceof IntArrayVector) {
			final int[] iArray = ((IntArrayVector) value).toIntArray();
			return iArray.length == 1 ? iArray[0] : iArray;
		}
		else if (value instanceof DoubleArrayVector) {
			final double[] dArray = ((DoubleArrayVector) value).toDoubleArray();
			return dArray.length == 1 ? dArray[0] : dArray;
		}
		else if (value instanceof LogicalArrayVector) {
			// consider wrapping to boolean[] ?
			final int[] lArray = ((LogicalArrayVector) value).toIntArray();
			return lArray.length == 1 ? lArray[0] : lArray;
		}
		else if (value instanceof StringArrayVector) {
			final String[] sArray = ((StringArrayVector) value).toArray();
			return sArray.length == 1 ? sArray[0] : sArray;
		}
		else if (value instanceof ExternalPtr<?>) {
			return ((ExternalPtr<?>) value).getInstance();
		}

		return value;
	}
	catch (final Exception exc) {
		return value.toString();
	}
}
 
开发者ID:scijava,项目名称:scripting-renjin,代码行数:43,代码来源:RenjinUtils.java


示例17: decode

import org.renjin.sexp.SEXP; //导入依赖的package包/类
@Override
public Object decode(final Object object) {
	// TODO if externalptr need to convert back to Java object
	if (object instanceof SEXP)
		return RenjinUtils.getJavaValue((SEXP) object);
	return object;
}
 
开发者ID:scijava,项目名称:scripting-renjin,代码行数:8,代码来源:RenjinScriptLanguage.java


示例18: getFunction

import org.renjin.sexp.SEXP; //导入依赖的package包/类
@Override
public Function getFunction(Context context, Symbol name) {
  SEXP value = getVariable(name);
  if(value instanceof Function) {
    return (Function)value;
  } else {
    return null;
  }
}
 
开发者ID:bedatadriven,项目名称:renjin-statet,代码行数:10,代码来源:ObjectFrame.java


示例19: toSymbol

import org.renjin.sexp.SEXP; //导入依赖的package包/类
private Symbol toSymbol(SEXP exp) {
  if(exp instanceof Symbol) {
    return (Symbol)exp;
  } else if(exp instanceof StringVector && exp.length() == 1) {
    return Symbol.get(  ((StringVector) exp).getElementAsString(0)  );
  } else {
    throw new IllegalArgumentException(exp.toString());
  }
}
 
开发者ID:bedatadriven,项目名称:renjin-statet,代码行数:10,代码来源:NamespaceDef.java


示例20: doApply

import org.renjin.sexp.SEXP; //导入依赖的package包/类
public static SEXP doApply(Context context, Environment environment, SEXP arg0, SEXP arg1)
    throws Exception
{
    if ((arg0 instanceof SEXP)&&((arg1 .length() == 0)||(arg1 instanceof Vector))) {
        Vector vector1 = ((Vector) WrapperRuntime.convertToVector(arg1));
        int length1 = vector1 .length();
        int currentElementIndex1 = 0;
        int cycles = 0;
        if (length1 == 0) {
            return LogicalVector.EMPTY;
        }
        if (length1 >cycles) {
            cycles = length1;
        }
        org.renjin.sexp.LogicalArrayVector.Builder builder = new org.renjin.sexp.LogicalArrayVector.Builder(cycles);
        for (int i = 0; (i!= cycles); i ++) {
            if (vector1 .isElementNA(currentElementIndex1)) {
                builder.setNA(i);
            } else {
                builder.set(i, Types.isListFactor(((SEXP) arg0), vector1 .isElementTrue(currentElementIndex1)));
            }
            currentElementIndex1 += 1;
            if (currentElementIndex1 == length1) {
                currentElementIndex1 = 0;
            }
        }
        if (length1 == cycles) {
            builder.copySomeAttributesFrom(vector1, Symbols.DIM, Symbols.DIMNAMES, Symbols.NAMES);
        }
        return builder.build();
    } else {
        throw new EvalException(String.format("Invalid argument:\n\tislistfactor(%s, %s)\n\tExpected:\n\tislistfactor(any, logical)", arg0 .getTypeName(), arg1 .getTypeName()));
    }
}
 
开发者ID:bedatadriven,项目名称:renjin-statet,代码行数:35,代码来源:R$primitive$islistfactor.java



注:本文中的org.renjin.sexp.SEXP类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java HeaderList类代码示例发布时间:2022-05-23
下一篇:
Java MemberChooserObject类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap