Пример #1
0
def createDataFrame(list_vec, colnames=None, name=None):
    """
    Create the DataFrame.
    
    list_vec : The list of RDotNet.Vector.
    colnames : The list of IronPython.
    name : The name.
    return : The expression.
    """
    if list_vec is None or len(list_vec) == 0:
        return None
    if colnames is None or len(list_vec) != len(colnames):
        colnames = []
        for i in xrange(len(list_vec)):
            colnames.append("V{0}".format(i + 1))
    _r_dataframe = SymbolicExpressionExtension.AsFunction(
        Engine.Evaluate("data.frame"))
    _r_colnames = SymbolicExpressionExtension.AsFunction(
        Engine.Evaluate("colnames"))
    dst = runFunction(_r_dataframe, list_vec, "dataframe")
    cln = runFunction(_r_colnames, [dst], "character")
    for i in xrange(len(list_vec)):
        cln[i] = colnames[i]
    if name != None:
        setSymbol(name, dst)
    return dst
Пример #2
0
def asFunction(var):
    if isFunction(var):
        return SymbolicExpressionExtension.AsFunction(var)
    else:
        return var
Пример #3
0
#
# Add reference.
#
import clr
clr.AddReferenceToFile("RDotNet.dll")
import RDotNet
from RDotNet import REngineExtension
from RDotNet import SymbolicExpressionExtension

#
# Initialize.
#
RDotNet.REngine.SetEnvironmentVariables(path.join(R_HOME, "bin\\x64"), R_HOME)
Engine = RDotNet.REngine.GetInstance()
_r_print = SymbolicExpressionExtension.AsFunction(Engine.Evaluate("print"))
print("REngine is initialized.")


#
# Functions.
#
def Initialize():
    """
    Initialize REngine.
    """
    global Engine
    if Engine is None:
        RDotNet.REngine.SetEnvironmentVariables(path.join(R_HOME, "bin\\x64"),
                                                R_HOME)
        Engine = RDotNet.REngine.GetInstance()