Exemplo n.º 1
0
 /// <summary>
 /// Is a slot name valid.
 /// </summary>
 /// <param name="slotName">the name of the slot</param>
 /// <returns>whether a slot name is present in the object</returns>
 public bool HasSlot(string slotName)
 {
     using (var s = new ProtectedPointer(Engine, GetFunction <Rf_mkString>()(slotName)))
     {
         return(this.GetFunction <R_has_slot>()(this.DangerousGetHandle(), s));
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// Gets a .NET representation as a two dimensional array of an R matrix
 /// </summary>
 /// <returns></returns>
 public T[,] ToArray()
 {
     using (var p = new ProtectedPointer(this))
     {
         return(GetArrayFast());
     }
 }
Exemplo n.º 3
0
 private SymbolicExpression createCallAndEvaluate(IntPtr argument)
 {
     using (var call = new ProtectedPointer(Engine, this.GetFunction <Rf_lcons>()(handle, argument)))
     {
         using (var result = evaluateCall(call))
         {
             return(new SymbolicExpression(Engine, result));
         }
     }
 }
Exemplo n.º 4
0
        private ProtectedPointer evaluateCall(IntPtr call)
        {
            ProtectedPointer result;
            bool             errorOccurred = false;

            try
            {
                result = new ProtectedPointer(Engine, Engine.GetFunction <R_tryEval>()(call, Engine.GlobalEnvironment.DangerousGetHandle(), out errorOccurred));
            }
            catch (Exception ex) // TODO: this is usually dubious to catch all that, but given the inner exception is preserved
            {
                throw new EvaluationException(Engine.LastErrorMessage, ex);
            }
            if (errorOccurred)
            {
                throw new EvaluationException(Engine.LastErrorMessage);
            }
            return(result);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Gets/sets the value of a slot
 /// </summary>
 /// <param name="name"></param>
 /// <returns></returns>
 public SymbolicExpression this[string name]
 {
     get
     {
         checkSlotName(name);
         IntPtr slotValue;
         using (var s = new ProtectedPointer(Engine, GetFunction <Rf_mkString>()(name)))
         {
             slotValue = this.GetFunction <R_do_slot>()(this.DangerousGetHandle(), s);
         }
         return(new SymbolicExpression(Engine, slotValue));
     }
     set
     {
         checkSlotName(name);
         using (var s = new ProtectedPointer(Engine, GetFunction <Rf_mkString>()(name)))
         {
             using (new ProtectedPointer(this))
             {
                 this.GetFunction <R_do_slot_assign>()(this.DangerousGetHandle(), s, value.DangerousGetHandle());
             }
         }
     }
 }