internal Vector(IRNode node)
        {
            if (node is IRVector vector)
            {
                switch (vector.ObjectType)
                {
                case RNodeType.Integer:
                    _type = VectorType.Integer;
                    break;

                case RNodeType.Real:
                    _type = VectorType.Real;
                    break;

                case RNodeType.String:
                    _type = VectorType.String;
                    break;

                default:
                    throw new NotSupportedException();
                }

                _vector = vector;
            }
            else
            {
                throw new ArgumentException();
            }
        }
Exemplo n.º 2
0
        internal void TreeViewSelectionChanged(IRNode thisItem)
        {
            if (thisItem == null)
            {
                return;
            }

            _rDoc.SelectedNodes.Clear();
            _rDoc.SelectedNodes.Add(thisItem);
            _eventagg.GetEvent <NodeSelectionChangedEvent>().Publish(thisItem);
        }
        public static string PrettyPrint(IRNode node)
        {
            StringWriter    sw     = new StringWriter();
            var             yaml   = new YamlWriter(sw);
            PAWriterVisitor pretty = new PAWriterVisitor();

            var context = new Context
            {
                _yaml = yaml
            };

            node.Accept(pretty, context);

            return(sw.ToString());
        }
Exemplo n.º 4
0
        private string[] ProcessNamesAttribute(IRNode item)
        {
            if (item is IRStringVector names)
            {
                string[] result = new string[names.Count];
                for (int i = 0; i < names.Count; i++)
                {
                    result[i] = names[i];
                }

                return(result);
            }

            throw new InvalidDataException();
        }
Exemplo n.º 5
0
        private bool ProcessClassAttribute(IRNode item)
        {
            if (item is IRStringVector classes)
            {
                for (int i = 0; i < classes.Count; i++)
                {
                    if (classes[i] == "data.frame")
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Exemplo n.º 6
0
        private void OnSelectedNodeChanged(IRNode obj)
        {
            if (obj == null)
            {
                SelectedItem = null;
                return;
            }

            SelectedItem = obj;

            //if(obj.NodeType == RNodeType.Transform)
            //{
            //    SelectedItem = obj as RTransformNode;
            //}
            //else if( obj.NodeType == RNodeType.Geometry)
            //{
            //    SelectedItem = obj as RGeometryNode;
            //}
        }
Exemplo n.º 7
0
 private void ProcessRowNamesAttribute(IRNode item)
 {
 }
Exemplo n.º 8
0
        internal DataFrame(IRNode node)
        {
            bool isDataFrame = false;

            string[] names = null;
            for (IRList attribute = node.Attribute as IRList; attribute != null; attribute = attribute.Tail)
            {
                string tagName = (attribute.Tag as IRString)?.String ?? "class";
                switch (tagName)
                {
                case "class":
                    isDataFrame = ProcessClassAttribute(attribute.Head);
                    break;

                case "names":
                    names = ProcessNamesAttribute(attribute.Head);
                    break;

                case "row.names":
                    ProcessRowNamesAttribute(attribute.Head);
                    break;
                }
            }

            if (!isDataFrame || names == null)
            {
                throw new InvalidDataException("The object is not a dataframe.");
            }

            if (node is IRGenericVector columns)
            {
                if (columns.Count != names.Length)
                {
                    throw new InvalidDataException("The number of column names doesn't match the number of columns.");
                }

                int rowCount        = -1;
                DataFrameColumn[] c = new DataFrameColumn[columns.Count];
                for (int i = 0; i < columns.Count; i++)
                {
                    if (columns[i] is IRVector item)
                    {
                        if (rowCount != item.Count)
                        {
                            if (rowCount == -1)
                            {
                                rowCount = (int)item.Count;
                            }
                            else
                            {
                                throw new InvalidDataException("The columns have different numbers of rows.");
                            }
                        }

                        c[i] = new DataFrameColumn(names[i], (IRVector)columns[i]);
                    }
                    else
                    {
                        throw new InvalidDataException();
                    }
                }

                Columns  = new DataFrameColumnCollection(c);
                RowCount = rowCount;
            }
            else
            {
                throw new InvalidDataException();
            }
        }
Exemplo n.º 9
0
        /// <summary>
        /// Reads a data frame from a serialized data source. This can either be a file created with
        /// the readRDS or the serialize function.
        /// </summary>
        /// <param name="stream">The stream from which to read the serialized data.</param>
        /// <returns>The unserialized data frame.</returns>
        public static DataFrame ReadFromStream(Stream stream)
        {
            IRNode node = Serializer.Unserialize(stream);

            return(new DataFrame(node));
        }
 /// <summary>
 /// Serialized the node to a stream and optionaly compresses the data with gzip.
 /// If compression is used, the stream content will be compatible with the readRDS function of R.
 /// If no compression is used, the stream content will be compatible with the unserialize function of R.
 /// </summary>
 /// <param name="node">The node to serialize.</param>
 /// <param name="stream">The stream to which to write the serialized data to.</param>
 /// <param name="compress">A value indicating whether to compress the serialized data with gzip.</param>
 public static void Serialize(IRNode node, Stream stream, bool compress)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Serialized the node to a stream and compresses the data with gzip.
 /// The stream content will be compatible with the readRDS function of R.
 /// </summary>
 /// <param name="node">The node to serialize.</param>
 /// <param name="stream">The stream to which to write the serialized data to.</param>
 public static void Serialize(IRNode node, Stream stream)
 {
     Serialize(node, stream, true);
 }
Exemplo n.º 12
0
        /// <summary>
        /// Reads a data frame from a serialized data source. This can either be a file created with
        /// the readRDS or the serialize function.
        /// </summary>
        /// <param name="stream">The stream from which to read the serialized data.</param>
        /// <returns>The unserialized vector.</returns>
        public static Vector ReadFromStream(Stream stream)
        {
            IRNode node = Serializer.Unserialize(stream);

            return(new Vector(node));
        }
Exemplo n.º 13
0
 private void OnContextCreated(IRNode obj)
 {
     ViewerInterop.ViewerEditor veditor = Editor as ViewerInterop.ViewerEditor;
     veditor.SubscribeEventForTransformNodeSelected(new ViewerInterop.OnTransformNodeSelected(OnTransformNodeSelectedHandler));
 }
Exemplo n.º 14
0
 public UI_RNode(IApplicationData data, IRNode currentItem, TreeViewItemViewModel parent) : base(parent, true)
 {
     _thisItem = currentItem;
     _data     = data;
 }
Exemplo n.º 15
0
 public ControlDiffContext(ControlPath path, IRNode theirs, bool isInComponent)
 {
     Theirs        = theirs;
     Path          = path;
     IsInComponent = isInComponent;
 }