Пример #1
0
        internal static SymbolicExpression ToVector(REngine engine, IEnumerable values)
        {
            if (values == null)
            {
                throw new ArgumentNullException("values", "values to transform to an R vector must not be null");
            }
            var ints     = values as IEnumerable <int>;
            var chars    = values as IEnumerable <string>;
            var cplxs    = values as IEnumerable <Complex>;
            var logicals = values as IEnumerable <bool>;
            var nums     = values as IEnumerable <double>;
            var raws     = values as IEnumerable <byte>;
            var sexpVec  = values as SymbolicExpression;

            if (sexpVec != null && sexpVec.IsVector())
            {
                return(sexpVec);
            }
            if (ints != null)
            {
                return(engine.CreateIntegerVector(ints));
            }
            if (chars != null)
            {
                return(engine.CreateCharacterVector(chars));
            }
            if (cplxs != null)
            {
                return(engine.CreateComplexVector(cplxs));
            }
            if (logicals != null)
            {
                return(engine.CreateLogicalVector(logicals));
            }
            if (nums != null)
            {
                return(engine.CreateNumericVector(nums));
            }
            if (raws != null)
            {
                return(engine.CreateRawVector(raws));
            }
            throw new NotSupportedException(string.Format("Cannot convert type {0} to an R vector", values.GetType()));
        }
Пример #2
0
        internal static SymbolicExpression ToVector(REngine engine, IEnumerable values)
        {
            if (values == null) throw new ArgumentNullException("values", "values to transform to an R vector must not be null");
            var ints = values as IEnumerable<int>;
            var chars = values as IEnumerable<string>;
            var cplxs = values as IEnumerable<Complex>;
            var logicals = values as IEnumerable<bool>;
            var nums = values as IEnumerable<double>;
            var raws = values as IEnumerable<byte>;
            var sexpVec = values as SymbolicExpression;

            if (sexpVec != null && sexpVec.IsVector())
                return sexpVec;
            if (ints != null)
                return engine.CreateIntegerVector(ints);
            if (chars != null)
                return engine.CreateCharacterVector(chars);
            if (cplxs != null)
                return engine.CreateComplexVector(cplxs);
            if (logicals != null)
                return engine.CreateLogicalVector(logicals);
            if (nums != null)
                return engine.CreateNumericVector(nums);
            if (raws != null)
                return engine.CreateRawVector(raws);
            throw new NotSupportedException(string.Format("Cannot convert type {0} to an R vector", values.GetType()));
        }