private static TimeSpan[] RdifftimeToTimespan(SymbolicExpression sexp, double[] values) { var units = RDotNetDataConverter.GetAttrib(sexp, "units")[0]; if (!_timediffUnits.Contains(units)) { throw new NotSupportedException("timediff units {0} are not supported"); } if (units == "secs") { return(Array.ConvertAll(values, TimeSpan.FromSeconds)); } if (units == "mins") { return(Array.ConvertAll(values, TimeSpan.FromMinutes)); } if (units == "hours") { return(Array.ConvertAll(values, TimeSpan.FromHours)); } if (units == "days") { return(Array.ConvertAll(values, TimeSpan.FromDays)); } if (units == "weeks") { return(Array.ConvertAll(values, x => TimeSpan.FromDays(x * 7))); } // This should never be reached. throw new NotSupportedException(); }
private static RDotNetDataConverter GetInstance(string pathToNativeSharedObj) { // Make sure this is set only once (RDotNet known limitation to one engine per session, effectively a singleton). if (singleton == null) singleton = new RDotNetDataConverter(pathToNativeSharedObj); return singleton; }
private static DateTime[] RPosixctToDateTime(SymbolicExpression sexp, double[] values) { var tz = RDotNetDataConverter.GetTzoneAttrib(sexp); if (!isSupportedTimeZone(tz)) { throw new NotSupportedException("POSIXct conversion supported only for UTC or unspecified (local) time zone, not for " + tz); } //number of seconds since 1970-01-01 UTC return(Array.ConvertAll(values, v => { bool utc = isUtc(tz); return ClrFacade.ForceDateKind(RDateOrigin + TimeSpan.FromTicks((long)(TimeSpan.TicksPerSecond * v)), utc); } )); }
private static object convertNumericVector(SymbolicExpression sexp) { var values = sexp.AsNumeric().ToArray(); var classNames = RDotNetDataConverter.GetClassAttrib(sexp); if (classNames != null) { if (classNames.Contains("Date")) { return(convertVector(RDateToDateTime(values))); } if (classNames.Contains("POSIXct")) { return(convertVector(RPosixctToDateTime(sexp, values))); } if (classNames.Contains("difftime")) { return(convertVector(RdifftimeToTimespan(sexp, values))); } } return(convertVector(values)); }