Beispiel #1
0
        public IConverter GetConverter(long pointer)
        {
            var sexp = engine.CreateFromNativeSexp(new IntPtr(pointer));

            _logger.DebugFormat("SEXP type: {0}", sexp.Type);

            if (_converters.TryGetValue(sexp.Type, out var factory))
            {
                return(factory(sexp));
            }

            throw new InvalidCastException($"Unable to find a converter from R type: {sexp.Type}");
        }
        public static SymbolicExpression ToExternalPointer(REngine engine, object instance)
        {
            if (instance == null)
            {
                return(engine.NilValue);
            }

            var tag = engine.CreateCharacterVector(new[] { NET_OBJ_TAG, instance.GetType().FullName });
            var ptr = engine.GetFunction <R_MakeExternalPtr>()(
                Marshal.GetIUnknownForObject(instance),
                tag.DangerousGetHandle(),
                engine.NilValue.DangerousGetHandle());

            var sexp = engine.CreateFromNativeSexp(ptr);

            return(sexp);
        }
Beispiel #3
0
 public SymbolicExpression CreateSymbolicExpression(IntPtr sexp)
 {
     return(engine.CreateFromNativeSexp(sexp));
 }