Beispiel #1
0
    /**
     * <summary>Copies values from another data</summary>
     * <param name="aRef">Reference to copy from</param>
     */
    public static RawVector copyFrom(IRawData aRef)
    {
        RawVector r = (RawVector)aRef;

        if (r == null)
        {
            throw new ArgumentException("Cannot copy from the instance of another type");
        }

        return(new RawVector(r.timestamp, new Vector3(r.x, r.y, r.z)));
    }
Beispiel #2
0
        public static void Start(REngine engine)
        {
            Console.WriteLine("\n\nExporting Objects\n\n");
            string RCodeString = string.Empty;

            //R character vector -- R.NET RDotNet.RDotNet.CharacterVector
            Console.WriteLine("\nR character vector\n");
            string[]        myStringArray     = new string[] { "PIDataLink", "PIProcessBook", "PIWebParts" };
            CharacterVector myCharacterVector = engine.CreateCharacterVector(myStringArray.AsEnumerable());

            engine.SetSymbol("mycharvector", myCharacterVector);
            engine.Evaluate("print(mycharvector)");


            //R integer vector -- R.NET RDotNet.NumericVector
            Console.WriteLine("\nR int vector\n");
            int[]         myIntegerArray  = new int[] { 4, 6, 10, 140, 54, 25 };
            IntegerVector myIntegerVector = engine.CreateIntegerVector(myIntegerArray);

            engine.SetSymbol("myintvector", myIntegerVector);
            engine.Evaluate("print(myintvector)");

            //R real vector -- R.NET RDotNet.NumericVector
            Console.WriteLine("\nR real vector\n");
            NumericVector myNumericVector = engine.CreateNumericVector(new double[] { 30.02, 29.99, 30.11, 29.97, 30.01, 29.99 });

            engine.SetSymbol("mynumvector", myNumericVector);
            engine.Evaluate("print(mynumvector)");

            //R complex vector -- R.NET RDotNet.ComplexVector
            Console.WriteLine("\nR complex vector\n");
            Complex[]     myComplexArray  = new Complex[] { Complex.FromPolarCoordinates(10, 0.524), new Complex(12, 6), new Complex(14, 3), (Complex)12.3m, Complex.One + Complex.One };
            ComplexVector myComplexVector = engine.CreateComplexVector(myComplexArray);

            engine.SetSymbol("mycomplexvector", myComplexVector);
            engine.Evaluate("print(mycomplexvector)");


            //R raw vector -- R.NET RDotNet.RawVector
            Console.WriteLine("\nR raw vector\n");
            byte[]    myByteArray = System.Text.Encoding.ASCII.GetBytes("u03a0");
            RawVector myRawVector = engine.CreateRawVector(myByteArray);

            engine.SetSymbol("myrawvector", myRawVector);
            engine.Evaluate("print(myrawvector)");

            //R logical vector -- R.NET RDotNet.LogicalVector
            Console.WriteLine("\nR logical vector\n");
            LogicalVector myLogicalVector = engine.CreateLogicalVector(new Boolean[] { true, false, false, false, true });

            engine.SetSymbol("mylogicalvector", myLogicalVector);
            engine.Evaluate("print(mylogicalvector)");
        }
        public static void Start(REngine engine)
        {
            Console.WriteLine("\n\nImporting Objects\n\n");

            string RCodeString = string.Empty;


            //R character vector -- R.NET RDotNet.CharacterVector
            RCodeString = "mycharvector<-c(\"hello\",\"bye\",\"OSIsoft\")";
            Console.WriteLine("\nR Code: " + RCodeString);
            engine.Evaluate(RCodeString);
            CharacterVector myCharacterVector = engine.GetSymbol("mycharvector").AsCharacter();

            string[] myStringArray = myCharacterVector.ToArray();
            Console.WriteLine("\nmyCharacterVector: ");
            int i = 1;

            foreach (string myCharacter in myCharacterVector)
            {
                Console.WriteLine(i + " value: " + myCharacter);
                i++;
            }


            //R int vector -- R.NET RDotNet.IntegerVector
            RCodeString = "myintvector<-1:10";
            Console.WriteLine("\nR Code: " + RCodeString);
            IntegerVector myIntegerVector = engine.Evaluate(RCodeString).AsInteger();

            int[] myIntegerArray = myIntegerVector.ToArray();
            Console.WriteLine("\nInteger Vector: ");
            i = 1;
            foreach (int myInteger in myIntegerVector)
            {
                Console.WriteLine(i + " value=" + myInteger);
                i++;
            }


            //R real vector -- R.NET RDotNet.NumericVector
            RCodeString = "myrealvector<-rnorm(5, 0, 1)";
            Console.WriteLine("\nR Code: " + RCodeString);
            NumericVector myNumericVector = engine.Evaluate(RCodeString).AsNumeric();

            double[] myDoubleArray = myNumericVector.ToArray();
            Console.WriteLine("\nNumeric Vector: ");
            i = 1;
            foreach (double myNumeric in myNumericVector)
            {
                Console.WriteLine(i + " value=" + myNumeric);
                i++;
            }

            //R complex vector -- R.NET RDotNet.ComplexVector
            RCodeString = "mycomplexvector<- 1:2 + 1i*(8:9)";
            Console.WriteLine("\nR Code: " + RCodeString);
            ComplexVector myComplexVector = engine.Evaluate(RCodeString).AsComplex();

            Complex[] myComplexArray = myComplexVector.ToArray();
            Console.WriteLine("\nComplex Vector: ");
            i = 1;
            foreach (Complex myComplex in myComplexVector)
            {
                Console.WriteLine(i + " value=" + myComplex.Imaginary + "i + " + myComplex.Real);
                i++;
            }

            //R raw vector -- R.NET RDotNet.RawVector
            RCodeString = "myrawvector<-charToRaw(\"u03a0\")";
            Console.WriteLine("\nR Code: " + RCodeString);
            RawVector myRawVector = engine.Evaluate(RCodeString).AsRaw();

            Console.WriteLine("\nRaw Vector: ");
            i = 1;
            foreach (Byte myByte in myRawVector)
            {
                Console.WriteLine(i + " value=" + myByte);
                i++;
            }

            //R logical vector -- R.NET RDotNet.LogicalVector
            RCodeString = "mylogicalvector<-c(FALSE, TRUE, FALSE, TRUE, FALSE)";
            Console.WriteLine("\nR Code: " + RCodeString);
            LogicalVector myLogicalVector = engine.Evaluate("c(FALSE, TRUE, FALSE, TRUE, FALSE)").AsLogical();

            Boolean[] myBooleanArray = myLogicalVector.ToArray();
            Console.WriteLine("\nLogical Vector: \n");
            i = 1;
            foreach (Boolean myBoolean in myLogicalVector)
            {
                Console.WriteLine(i + " value=" + myBoolean.ToString());
                i++;
            }

            //Close R.NET connection
            engine.Dispose();
        }