private static RData checkEmptyValue(JToken jparent, String type, String rclass, String name) { RData data = null; if (!(jparent["value"] == null)) { return(null); } if (type == Constants.TYPE_MATRIX) { if (rclass == Constants.RCLASS_NUMERIC) { data = new RNumericMatrix(name, null); } else if (rclass == Constants.RCLASS_CHARACTER) { data = new RStringMatrix(name, null); } else if (rclass == Constants.RCLASS_BOOLEAN) { data = new RBooleanMatrix(name, null); } else { data = new RNumericMatrix(name, null); } } else if (type == Constants.TYPE_VECTOR) { if (rclass == Constants.RCLASS_NUMERIC) { data = new RNumericVector(name, null); } else if (rclass == Constants.RCLASS_CHARACTER) { data = new RStringVector(name, null); } else if (rclass == Constants.RCLASS_BOOLEAN) { data = new RBooleanVector(name, null); } else if (rclass == Constants.RCLASS_DATE) { data = new RDateVector(name, null, ""); } else { data = new RNumericVector(name, null); } } else if (type == Constants.TYPE_PRIMITIVE) { if (rclass == Constants.RCLASS_NUMERIC) { data = new RNumeric(name, 0); } else if (rclass == Constants.RCLASS_CHARACTER) { data = new RString(name, null); } else if (rclass == Constants.RCLASS_BOOLEAN) { data = new RBoolean(name, false); } else { data = new RNumeric(name, 0); } } else if (type == Constants.TYPE_DATE) { data = new RDate(name, null, ""); } else if (type == Constants.TYPE_FACTOR) { data = new RFactor(name, null); } else if (type == Constants.TYPE_DATAFRAME) { data = new RDataFrame(name, null); } else if (type == Constants.TYPE_LIST) { data = new RList(name, null); } return(data); }
private static RData checkEmptyValue(JToken jparent, String type, String rclass, String name) { RData data = null; if (!(jparent["value"] == null)) { return null; } if (type == Constants.TYPE_MATRIX) { if (rclass == Constants.RCLASS_NUMERIC) { data = new RNumericMatrix(name, null); } else if (rclass == Constants.RCLASS_CHARACTER) { data = new RStringMatrix(name, null); } else if (rclass == Constants.RCLASS_BOOLEAN) { data = new RBooleanMatrix(name, null); } else { data = new RNumericMatrix(name, null); } } else if (type == Constants.TYPE_VECTOR) { if (rclass == Constants.RCLASS_NUMERIC) { data = new RNumericVector(name, null); } else if (rclass == Constants.RCLASS_CHARACTER) { data = new RStringVector(name, null); } else if (rclass == Constants.RCLASS_BOOLEAN) { data = new RBooleanVector(name, null); } else if (rclass == Constants.RCLASS_DATE) { data = new RDateVector(name, null, ""); } else { data = new RNumericVector(name, null); } } else if (type == Constants.TYPE_PRIMITIVE) { if (rclass == Constants.RCLASS_NUMERIC) { data = new RNumeric(name, 0); } else if (rclass == Constants.RCLASS_CHARACTER) { data = new RString(name, null); } else if (rclass == Constants.RCLASS_BOOLEAN) { data = new RBoolean(name, false); } else { data = new RNumeric(name, 0); } } else if (type == Constants.TYPE_DATE) { data = new RDate(name, null, ""); } else if (type == Constants.TYPE_FACTOR) { data = new RFactor(name, null); } else if (type == Constants.TYPE_DATAFRAME) { data = new RDataFrame(name, null); } else if (type == Constants.TYPE_LIST) { data = new RList(name, null); } return data; }
/// <summary> /// Create the appropriate RData class representing a matrix (RNumericMatrix, RBooleanMatrix, RStringMatrix) /// </summary> /// <param name="name">name of the RData instance</param> /// <param name="jparent">Parent json.net object</param> /// <returns>RData object</returns> /// <remarks></remarks> public static RData parseMatrix(String name, JToken jparent) { int primitiveType = -1; int iRows = -1; int iCols = -1; RData data = null; if (!(jparent["value"] == null)) { JArray jvalues = jparent["value"].Value <JArray>(); iRows = jvalues.Count - 1; foreach (JArray jsubvalues in jvalues) { iCols = jsubvalues.Count - 1; foreach (var j in jsubvalues) { if (j.Type != JTokenType.Null) { if ((j.Type == JTokenType.Float) || (j.Type == JTokenType.Integer)) { primitiveType = Constants._NUMERIC; } else if (j.Type == JTokenType.String) { primitiveType = Constants._CHARACTER; } else if (j.Type == JTokenType.Boolean) { primitiveType = Constants._LOGICAL; } } if (primitiveType != -1) { break; } } if (primitiveType != -1) { break; } } } if (iRows < 0 | iCols < 0 | primitiveType < 0) { return(data); } List <List <Double?> > numRowList = new List <List <Double?> >(); List <List <String> > charRowList = new List <List <String> >(); List <List <Boolean?> > logRowList = new List <List <Boolean?> >(); List <Double?> numColList = new List <Double?>(); List <String> charColList = new List <String>(); List <Boolean?> logColList = new List <Boolean?>(); if (!(jparent["value"] == null)) { JArray jvalues = jparent["value"].Value <JArray>(); foreach (JArray jsubvalues in jvalues) { if (primitiveType == Constants._NUMERIC) { numColList = new List <Double?>(); } else if (primitiveType == Constants._CHARACTER) { charColList = new List <String>(); } else if (primitiveType == Constants._LOGICAL) { logColList = new List <Boolean?>(); } foreach (var j in jsubvalues) { if (j.Type != JTokenType.Null) { if (primitiveType == Constants._NUMERIC) { numColList.Add(j.Value <double>()); } else if (primitiveType == Constants._CHARACTER) { charColList.Add(j.Value <string>()); } else if (primitiveType == Constants._LOGICAL) { logColList.Add(j.Value <bool>()); } } else { if (primitiveType == Constants._NUMERIC) { numColList.Add(null); } else if (primitiveType == Constants._CHARACTER) { charColList.Add(null); } else if (primitiveType == Constants._LOGICAL) { logColList.Add(null); } } } if (primitiveType == Constants._NUMERIC) { numRowList.Add(numColList); } else if (primitiveType == Constants._CHARACTER) { charRowList.Add(charColList); } else if (primitiveType == Constants._LOGICAL) { logRowList.Add(logColList); } } } if (primitiveType == Constants._NUMERIC) { data = new RNumericMatrix(name, numRowList); } else if (primitiveType == Constants._CHARACTER) { data = new RStringMatrix(name, charRowList); } else if (primitiveType == Constants._LOGICAL) { data = new RBooleanMatrix(name, logRowList); } return(data); }
/// <summary> /// Create the appropriate RData class representing a matrix (RNumericMatrix, RBooleanMatrix, RStringMatrix) /// </summary> /// <param name="name">name of the RData instance</param> /// <param name="jparent">Parent json.net object</param> /// <returns>RData object</returns> /// <remarks></remarks> public static RData parseMatrix(String name, JToken jparent) { int primitiveType = -1; int iRows = -1; int iCols = -1; RData data = null; if (!(jparent["value"] == null)) { JArray jvalues = jparent["value"].Value<JArray>(); iRows = jvalues.Count - 1; foreach (JArray jsubvalues in jvalues) { iCols = jsubvalues.Count - 1; foreach (var j in jsubvalues) { if (j.Type != JTokenType.Null) { if ((j.Type == JTokenType.Float) || (j.Type == JTokenType.Integer)) { primitiveType = Constants._NUMERIC; } else if (j.Type == JTokenType.String) { primitiveType = Constants._CHARACTER; } else if (j.Type == JTokenType.Boolean) { primitiveType = Constants._LOGICAL; } } if (primitiveType != -1) { break; } } if (primitiveType != -1) { break; } } } if (iRows < 0 | iCols < 0 | primitiveType < 0) { return data; } List<List<Double?>> numRowList = new List<List<Double?>>(); List<List<String>> charRowList = new List<List<String>>(); List<List<Boolean?>> logRowList = new List<List<Boolean?>>(); List<Double?> numColList = new List<Double?>(); List<String> charColList = new List<String>(); List<Boolean?> logColList = new List<Boolean?>(); if (!(jparent["value"] == null)) { JArray jvalues = jparent["value"].Value<JArray>(); foreach (JArray jsubvalues in jvalues) { if (primitiveType == Constants._NUMERIC) { numColList = new List<Double?>(); } else if (primitiveType == Constants._CHARACTER) { charColList = new List<String>(); } else if (primitiveType == Constants._LOGICAL) { logColList = new List<Boolean?>(); } foreach (var j in jsubvalues) { if (j.Type != JTokenType.Null) { if (primitiveType == Constants._NUMERIC) { numColList.Add(j.Value<double>()); } else if (primitiveType == Constants._CHARACTER) { charColList.Add(j.Value<string>()); } else if (primitiveType == Constants._LOGICAL) { logColList.Add(j.Value<bool>()); } } else { if (primitiveType == Constants._NUMERIC) { numColList.Add(null); } else if (primitiveType == Constants._CHARACTER) { charColList.Add(null); } else if (primitiveType == Constants._LOGICAL) { logColList.Add(null); } } } if (primitiveType == Constants._NUMERIC) { numRowList.Add(numColList); } else if (primitiveType == Constants._CHARACTER) { charRowList.Add(charColList); } else if (primitiveType == Constants._LOGICAL) { logRowList.Add(logColList); } } } if (primitiveType == Constants._NUMERIC) { data = new RNumericMatrix(name, numRowList); } else if (primitiveType == Constants._CHARACTER) { data = new RStringMatrix(name, charRowList); } else if (primitiveType == Constants._LOGICAL) { data = new RBooleanMatrix(name, logRowList); } return data; }