Пример #1
0
 REXP parseEvalResponse(Rpacket rp) throws RSrvException {
   int rxo = 0;
   byte[] pc = rp.getCont();
   if (rsrvVersion > 100) {
       /* since 0101 eval responds correctly by using DT_SEXP type/len header which is 4 bytes long */
     rxo = 4;
     /* we should check parameter type (should be DT_SEXP) and fail if it's not */
     if (pc[0] != Rtalk.DT_SEXP && pc[0] != (Rtalk.DT_SEXP | Rtalk.DT_LARGE))
       throw new RSrvException(
           this,
           "Error while processing eval output: SEXP (type "
               + Rtalk.DT_SEXP
               + ") expected but found result type "
               + pc[0]
               + ".");
     if (pc[0] == (Rtalk.DT_SEXP | Rtalk.DT_LARGE)) rxo = 8; // large data need skip of 8 bytes
     /* warning: we are not checking or using the length - we assume that only the one SEXP is returned. This is true for the current CMD_eval implementation, but may not be in the future. */
   }
   REXP rx = null;
   if (pc.length > rxo) {
     rx = new REXP();
     REXP.parseREXP(rx, pc, rxo);
   }
   return rx;
 }
Пример #2
0
 /**
  * assign a content of a REXP to a symbol in R. The symbol is created if it doesn't exist already.
  *
  * @param 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").
  * @param ct contents. currently only basic types (int, double, int[], double[]) are supported.
  * @return <code>true</code> on success, otherwise <code>false</code>
  */
 public void assign(String sym, REXP r) throws RSrvException {
   if (!connected || rt == null) throw new RSrvException(this, "Not connected");
   int rl = r.getBinaryLength();
   byte[] symn = sym.getBytes();
   int sl = symn.length + 1;
   if ((sl & 3) > 0) sl = (sl & 0xfffffc) + 4; // make sure the symbol length is divisible by 4
   byte[] rq = new byte[sl + rl + ((rl > 0xfffff0) ? 12 : 8)];
   int ic;
   for (ic = 0; ic < symn.length; ic++) rq[ic + 4] = symn[ic];
   while (ic < sl) {
     rq[ic + 4] = 0;
     ic++;
   }
   ; // pad with 0
   Rtalk.setHdr(Rtalk.DT_STRING, sl, rq, 0);
   Rtalk.setHdr(Rtalk.DT_SEXP, rl, rq, sl + 4);
   r.getBinaryRepresentation(rq, sl + ((rl > 0xfffff0) ? 12 : 8));
   Rpacket rp = rt.request(Rtalk.CMD_setSEXP, rq);
   if (rp != null && rp.isOk()) return;
   throw new RSrvException(this, "assign failed", rp);
 }