Logo Search packages:      
Sourcecode: rserve version File versions  Download package

void org::rosuda::JRclient::Rconnection::assign ( String  sym,
String  ct 
) throws RSrvException [inline]

assign a string value to a symbol in R. The symbol is created if it doesn't exist already.

Parameters:
sym symbol name. Currently assign uses CMD_setSEXP command of Rserve, i.e. the symbol value is NOT parsed. It is the responsibility of the user to make sure that the symbol name is valid in R (recall the difference between a symbol and an expression!). In fact R will always create the symbol, but it may not be accessible (examples: "bar\nfoo" or "bar$foo").
ct contents
Returns:
true on success, otherwise false

Definition at line 230 of file Rconnection.java.

References org::rosuda::JRclient::Rpacket::isOk(), and org::rosuda::JRclient::Rtalk::request().

Referenced by assign().

                                                                   {
            if (!connected || rt==null)
            throw new RSrvException(this,"Not connected");
        byte[] symn=sym.getBytes();
        byte[] ctn=ct.getBytes();
        int sl=symn.length+1;
        int cl=ctn.length+1;
        if ((sl&3)>0) sl=(sl&0xfffffc)+4; // make sure the symbol length is divisible by 4
        if ((cl&3)>0) cl=(cl&0xfffffc)+4; // make sure the content length is divisible by 4
        byte[] rq=new byte[sl+4+cl+4];
        int ic;
        for(ic=0;ic<symn.length;ic++) rq[ic+4]=symn[ic];
        while (ic<sl) { rq[ic+4]=0; ic++; }
        for(ic=0;ic<ctn.length;ic++) rq[ic+sl+8]=ctn[ic];
        while (ic<cl) { rq[ic+sl+8]=0; ic++; }
            Rtalk.setHdr(Rtalk.DT_STRING,sl,rq,0);
            Rtalk.setHdr(Rtalk.DT_STRING,cl,rq,sl+4);
            Rpacket rp=rt.request(Rtalk.CMD_setSEXP,rq);
        if (rp!=null && rp.isOk()) return;
        throw new RSrvException(this,"assign failed",rp);
    }


Generated by  Doxygen 1.6.0   Back to index