ProcessTimeseriesResponse = function(tsResponse, tsName) { if (!is.null(tsResponse)) { # Any request dealing with a single user created item returns a # DSUserObjectResponse. This has ResponseStatus property that indicates # success or failure if (tsResponse$ResponseStatus != DSUserObjectResponseStatus$UserObjectSuccess) print(paste('Request failed for timeseries', tsName, 'with error ', names(DSUserObjectResponseStatus)[tsResponse$ResponseStatus + 1], ': ', tsResponse$ErrorMessage, '\n\n')) else if (!is.null(tsResponse$UserObject)) # The timeseries item won't be returned if you set SkipItem true in CreateItem or UpdateItem { # Here we simply display the timeseries data using a dataframe. tsItem = tsResponse$UserObject metadata = c (Id = tsItem$Id, Desc = tsItem$Description, LastModified = as.character(tsItem$LastModified), StartDate = ifelse (!is.null(tsItem$DateInfo), as.character(tsItem$DateInfo$StartDate), NULL), EndDate = ifelse(!is.null(tsItem$DateInfo),as.character(tsItem$DateInfo$EndDate), NULL), Frequency = ifelse(!is.null(tsItem$DateInfo), names(DSUserObjectFrequency)[tsItem$DateInfo$Frequency + 1], NULL), NoOfValues = ifelse(!is.null(tsItem$DateRange), tsItem$DateRange$ValuesCount , 0)) df = data.frame(metadata) print(df) if (!is.null(tsItem$DateRange)) { df = data.frame(Dates = sapply(tsItem$DateRange$Dates, FUN = function(x) { return (as.character(x)) }), Values = sapply(tsItem$DateRange$Values, FUN = function(x) { ifelse (is.null(x), return (NA_character_ ), return (x) )} )) # Values if NULL, is printed as because, while # convertind list to vector either by using as.vector or sapply, # the NULL values in the list are deleted. and thus there will # be mismatch in no of rows and cannot be put in a dataframe print(df) } } } else print(paste('Timeseries ', tsName, ' successfully updated but item details not returned.')) } testID = 'TSVVV023' # Modifying 'TSVVV023' it to be a daily frequency # series with data from 2000 until 2020. # we'll get the list of supported dates between the start and end date. startDate = as.Date('2000-01-01') endDate = as.Date('2020-12-31') freq = DSUserObjectFrequency$Daily print('Requesting GetTimeseriesDateRange to get supported dates from 2001-01-0 to 2020-12-31 at daily frequency.') dateRangeResp = timeseriesClient$GetTimeseriesDateRange(startDate, endDate, freq) # With the list of supported dates returned from GetTimeseriesDateRange, # you would then create an array of values associated with the given dates # from your data source. # For this example, we'll just populate an array of test values randomly # between 10.00 and 200.00 with two decimal places if (!(is.null(dateRangeResp)) & dateRangeResp$ResponseStatus == DSUserObjectResponseStatus$UserObjectSuccess & !(is.null(dateRangeResp$Dates))) { # We'll just take the count of the number of dates and generate random # data to simulate us retrieving corresponding values from your data source. datesCount = length(dateRangeResp$Dates) values = runif(datesCount, 10, 200) # an array datesCount long with random values between 10 and 200 with 2 decimal places } # set the new dates, frequency and values on our existing timeseries object # Note: Datastream takes the StartDate, Frequency and Values and creates the # timeseries based only using these parameters. The EndDate is not actually used internally # other than for logging purposes. The true end date is calculated based on the # start date, frequency and list of values. Supply too few or too many values # and the mainframe will accept them and set the end date accordingly based # on the given frequency for the item. # To demonstrate this, we deliberately set the enddate to be a date other than # 2020-12-31. The response item will give the true end date as calculated # (2020-12-31) testTs$DataInput = DSTimeSeriesDataInput$new(startDate, as.Date('2005-12-31'), freq, values) testTs$DisplayName = 'Modifying timeseries to be daily frequency' testTs$DataInput$Frequency = DSUserObjectFrequency$Daily # and finally call UpdateItem print(paste('Updating our timeseries', testID, 'to have daily frequency.')) tsResp = timeseriesClient$UpdateItem(testTs) # we will just display the updated timeseries object returned # from the mainframe. ProcessTimeseriesResponse(tsResp, testID)