R Under development (unstable) (2024-03-11 r86098 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > 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.')) + } > > library(DatastreamR) > > # Login using Configuration > timeseriesClient = TimeSeriesClient$new('Config.ini') INFO [2024-03-13 10:17:41] DSConnect.R DSConnect$getToken :Getting Token and Token Expiry INFO [2024-03-13 10:17:42] DSConnect.R DSConnect$getJsonResponse Web response received > timeseriesClient$useNaNforNotANumber = TRUE > > getItemResp = timeseriesClient$GetItem('TS000001') INFO [2024-03-13 10:17:42] DatastreamUserCreated_TimeSeries.R TimeSeriesClient$GetItem Requesting TS000001 INFO [2024-03-13 10:17:42] DSConnect.R DSConnect$getJsonResponse Web response received INFO [2024-03-13 10:17:42] DatastreamUserCreated_TimeSeries.R TimeSeriesClient$GetItem TS000001 returned a response > > # Let's use ProcessTimeseriesResponse to perfom general processing of the > # DSUserObjectResponse as we will be handling a few timeseries responses. > # See the comments in ProcessTimeseriesResponse for a description of handling > # a response > ProcessTimeseriesResponse(getItemResp, 'TS000001') metadata Id TS000001 Desc Cross-section average of OECD countries inflation LastModified 2023-03-01 StartDate 1980-12-15 EndDate 2022-04-15 Frequency Monthly NoOfValues 497 Dates Values 1 1980-12-01 NaN 2 1981-01-01 NaN 3 1981-02-01 NaN 4 1981-03-01 NaN 5 1981-04-01 NaN 6 1981-05-01 NaN 7 1981-06-01 NaN 8 1981-07-01 NaN 9 1981-08-01 NaN 10 1981-09-01 NaN 11 1981-10-01 NaN 12 1981-11-01 NaN 13 1981-12-01 NaN 14 1982-01-01 NaN 15 1982-02-01 NaN 16 1982-03-01 NaN 17 1982-04-01 NaN 18 1982-05-01 NaN 19 1982-06-01 NaN 20 1982-07-01 NaN 21 1982-08-01 NaN 22 1982-09-01 NaN 23 1982-10-01 NaN 24 1982-11-01 NaN 25 1982-12-01 NaN 26 1983-01-01 NaN 27 1983-02-01 NaN 28 1983-03-01 NaN 29 1983-04-01 NaN 30 1983-05-01 NaN 31 1983-06-01 NaN 32 1983-07-01 NaN 33 1983-08-01 NaN 34 1983-09-01 NaN 35 1983-10-01 NaN 36 1983-11-01 NaN 37 1983-12-01 NaN 38 1984-01-01 NaN 39 1984-02-01 NaN 40 1984-03-01 NaN 41 1984-04-01 NaN 42 1984-05-01 NaN 43 1984-06-01 NaN 44 1984-07-01 NaN 45 1984-08-01 NaN 46 1984-09-01 NaN 47 1984-10-01 NaN 48 1984-11-01 NaN 49 1984-12-01 NaN 50 1985-01-01 NaN 51 1985-02-01 NaN 52 1985-03-01 NaN 53 1985-04-01 NaN 54 1985-05-01 NaN 55 1985-06-01 NaN 56 1985-07-01 NaN 57 1985-08-01 NaN 58 1985-09-01 NaN 59 1985-10-01 NaN 60 1985-11-01 -0.254 61 1985-12-01 -0.281 62 1986-01-01 -0.308 63 1986-02-01 -0.337 64 1986-03-01 -0.367 65 1986-04-01 -0.398 66 1986-05-01 -0.428 67 1986-06-01 -0.458 68 1986-07-01 -0.489 69 1986-08-01 -0.519 70 1986-09-01 -0.546 71 1986-10-01 -0.574 72 1986-11-01 -0.600 73 1986-12-01 -0.626 74 1987-01-01 -0.652 75 1987-02-01 -0.674 76 1987-03-01 -0.694 77 1987-04-01 -0.711 78 1987-05-01 -0.726 79 1987-06-01 -0.739 80 1987-07-01 -0.749 81 1987-08-01 -0.755 82 1987-09-01 -0.761 83 1987-10-01 -0.765 84 1987-11-01 -0.768 85 1987-12-01 -0.769 86 1988-01-01 -0.768 87 1988-02-01 -0.766 88 1988-03-01 -0.761 89 1988-04-01 -0.757 90 1988-05-01 -0.752 91 1988-06-01 -0.744 92 1988-07-01 -0.734 93 1988-08-01 -0.725 94 1988-09-01 -0.715 95 1988-10-01 -0.703 96 1988-11-01 -0.692 97 1988-12-01 -0.681 98 1989-01-01 -0.668 99 1989-02-01 -0.655 100 1989-03-01 -0.643 101 1989-04-01 -0.626 102 1989-05-01 -0.606 103 1989-06-01 -0.586 104 1989-07-01 -0.565 105 1989-08-01 -0.543 106 1989-09-01 -0.519 107 1989-10-01 -0.494 108 1989-11-01 -0.469 109 1989-12-01 -0.443 110 1990-01-01 -0.414 111 1990-02-01 -0.386 112 1990-03-01 -0.358 113 1990-04-01 -0.334 114 1990-05-01 -0.311 115 1990-06-01 -0.288 116 1990-07-01 -0.264 117 1990-08-01 -0.237 118 1990-09-01 -0.208 119 1990-10-01 -0.175 120 1990-11-01 -0.145 121 1990-12-01 -0.119 122 1991-01-01 -0.091 123 1991-02-01 -0.062 124 1991-03-01 -0.034 125 1991-04-01 -0.005 126 1991-05-01 0.025 127 1991-06-01 0.056 128 1991-07-01 0.088 129 1991-08-01 0.116 130 1991-09-01 0.137 131 1991-10-01 0.156 132 1991-11-01 0.176 133 1991-12-01 0.195 134 1992-01-01 0.211 135 1992-02-01 0.225 136 1992-03-01 0.238 137 1992-04-01 0.248 138 1992-05-01 0.253 139 1992-06-01 0.255 140 1992-07-01 0.250 141 1992-08-01 0.242 142 1992-09-01 0.233 143 1992-10-01 0.221 144 1992-11-01 0.206 145 1992-12-01 0.191 146 1993-01-01 0.178 147 1993-02-01 0.164 148 1993-03-01 0.150 149 1993-04-01 0.137 150 1993-05-01 0.122 151 1993-06-01 0.107 152 1993-07-01 0.092 153 1993-08-01 0.078 154 1993-09-01 0.063 155 1993-10-01 0.048 156 1993-11-01 0.032 157 1993-12-01 0.016 158 1994-01-01 -0.004 159 1994-02-01 -0.025 160 1994-03-01 -0.046 161 1994-04-01 -0.070 162 1994-05-01 -0.095 163 1994-06-01 -0.118 164 1994-07-01 -0.141 165 1994-08-01 -0.162 166 1994-09-01 -0.184 167 1994-10-01 -0.208 168 1994-11-01 -0.232 169 1994-12-01 -0.255 170 1995-01-01 -0.280 171 1995-02-01 -0.305 172 1995-03-01 -0.330 173 1995-04-01 -0.351 174 1995-05-01 -0.370 175 1995-06-01 -0.389 176 1995-07-01 -0.412 177 1995-08-01 -0.437 178 1995-09-01 -0.465 179 1995-10-01 -0.495 180 1995-11-01 -0.524 181 1995-12-01 -0.551 182 1996-01-01 -0.580 183 1996-02-01 -0.608 184 1996-03-01 -0.633 185 1996-04-01 -0.657 186 1996-05-01 -0.680 187 1996-06-01 -0.705 188 1996-07-01 -0.730 189 1996-08-01 -0.753 190 1996-09-01 -0.772 191 1996-10-01 -0.785 192 1996-11-01 -0.799 193 1996-12-01 -0.811 194 1997-01-01 -0.819 195 1997-02-01 -0.828 196 1997-03-01 -0.842 197 1997-04-01 -0.857 198 1997-05-01 -0.870 199 1997-06-01 -0.879 200 1997-07-01 -0.884 201 1997-08-01 -0.884 202 1997-09-01 -0.884 203 1997-10-01 -0.881 204 1997-11-01 -0.876 205 1997-12-01 -0.871 206 1998-01-01 -0.869 207 1998-02-01 -0.864 208 1998-03-01 -0.859 209 1998-04-01 -0.852 210 1998-05-01 -0.843 211 1998-06-01 -0.835 212 1998-07-01 -0.829 213 1998-08-01 -0.827 214 1998-09-01 -0.824 215 1998-10-01 -0.822 216 1998-11-01 -0.819 217 1998-12-01 -0.820 218 1999-01-01 -0.819 219 1999-02-01 -0.818 220 1999-03-01 -0.814 221 1999-04-01 -0.808 222 1999-05-01 -0.805 223 1999-06-01 -0.802 224 1999-07-01 -0.801 225 1999-08-01 -0.797 226 1999-09-01 -0.793 227 1999-10-01 -0.786 228 1999-11-01 -0.779 229 1999-12-01 -0.768 230 2000-01-01 -0.757 231 2000-02-01 -0.746 232 2000-03-01 -0.734 233 2000-04-01 -0.726 234 2000-05-01 -0.717 235 2000-06-01 -0.703 236 2000-07-01 -0.685 237 2000-08-01 -0.669 238 2000-09-01 -0.650 239 2000-10-01 -0.632 240 2000-11-01 -0.612 241 2000-12-01 -0.596 242 2001-01-01 -0.579 243 2001-02-01 -0.562 244 2001-03-01 -0.546 245 2001-04-01 -0.525 246 2001-05-01 -0.501 247 2001-06-01 -0.479 248 2001-07-01 -0.462 249 2001-08-01 -0.445 250 2001-09-01 -0.430 251 2001-10-01 -0.419 252 2001-11-01 -0.414 253 2001-12-01 -0.408 254 2002-01-01 -0.397 255 2002-02-01 -0.387 256 2002-03-01 -0.373 257 2002-04-01 -0.358 258 2002-05-01 -0.347 259 2002-06-01 -0.340 260 2002-07-01 -0.330 261 2002-08-01 -0.320 262 2002-09-01 -0.311 263 2002-10-01 -0.297 264 2002-11-01 -0.282 265 2002-12-01 -0.267 266 2003-01-01 -0.253 267 2003-02-01 -0.237 268 2003-03-01 -0.222 269 2003-04-01 -0.214 270 2003-05-01 -0.210 271 2003-06-01 -0.205 272 2003-07-01 -0.201 273 2003-08-01 -0.194 274 2003-09-01 -0.188 275 2003-10-01 -0.184 276 2003-11-01 -0.179 277 2003-12-01 -0.173 278 2004-01-01 -0.165 279 2004-02-01 -0.161 280 2004-03-01 -0.159 281 2004-04-01 -0.154 282 2004-05-01 -0.142 283 2004-06-01 -0.128 284 2004-07-01 -0.112 285 2004-08-01 -0.101 286 2004-09-01 -0.092 287 2004-10-01 -0.080 288 2004-11-01 -0.071 289 2004-12-01 -0.067 290 2005-01-01 -0.067 291 2005-02-01 -0.069 292 2005-03-01 -0.070 293 2005-04-01 -0.068 294 2005-05-01 -0.072 295 2005-06-01 -0.082 296 2005-07-01 -0.088 297 2005-08-01 -0.092 298 2005-09-01 -0.094 299 2005-10-01 -0.096 300 2005-11-01 -0.103 301 2005-12-01 -0.106 302 2006-01-01 -0.106 303 2006-02-01 -0.107 304 2006-03-01 -0.111 305 2006-04-01 -0.116 306 2006-05-01 -0.121 307 2006-06-01 -0.122 308 2006-07-01 -0.120 309 2006-08-01 -0.118 310 2006-09-01 -0.121 311 2006-10-01 -0.127 312 2006-11-01 -0.126 313 2006-12-01 -0.123 314 2007-01-01 -0.125 315 2007-02-01 -0.126 316 2007-03-01 -0.124 317 2007-04-01 -0.121 318 2007-05-01 -0.115 319 2007-06-01 -0.107 320 2007-07-01 -0.102 321 2007-08-01 -0.100 322 2007-09-01 -0.092 323 2007-10-01 -0.080 324 2007-11-01 -0.060 325 2007-12-01 -0.039 326 2008-01-01 -0.014 327 2008-02-01 0.009 328 2008-03-01 0.035 329 2008-04-01 0.064 330 2008-05-01 0.103 331 2008-06-01 0.145 332 2008-07-01 0.190 333 2008-08-01 0.231 334 2008-09-01 0.269 335 2008-10-01 0.302 336 2008-11-01 0.321 337 2008-12-01 0.330 338 2009-01-01 0.336 339 2009-02-01 0.343 340 2009-03-01 0.345 341 2009-04-01 0.341 342 2009-05-01 0.324 343 2009-06-01 0.303 344 2009-07-01 0.278 345 2009-08-01 0.256 346 2009-09-01 0.236 347 2009-10-01 0.211 348 2009-11-01 0.194 349 2009-12-01 0.183 350 2010-01-01 0.178 351 2010-02-01 0.171 352 2010-03-01 0.165 353 2010-04-01 0.160 354 2010-05-01 0.159 355 2010-06-01 0.156 356 2010-07-01 0.151 357 2010-08-01 0.145 358 2010-09-01 0.136 359 2010-10-01 0.130 360 2010-11-01 0.128 361 2010-12-01 0.128 362 2011-01-01 0.127 363 2011-02-01 0.127 364 2011-03-01 0.132 365 2011-04-01 0.135 366 2011-05-01 0.134 367 2011-06-01 0.131 368 2011-07-01 0.129 369 2011-08-01 0.127 370 2011-09-01 0.134 371 2011-10-01 0.144 372 2011-11-01 0.151 373 2011-12-01 0.152 374 2012-01-01 0.153 375 2012-02-01 0.154 376 2012-03-01 0.150 377 2012-04-01 0.146 378 2012-05-01 0.141 379 2012-06-01 0.135 380 2012-07-01 0.129 381 2012-08-01 0.126 382 2012-09-01 0.119 383 2012-10-01 0.102 384 2012-11-01 0.073 385 2012-12-01 0.044 386 2013-01-01 0.009 387 2013-02-01 -0.028 388 2013-03-01 -0.068 389 2013-04-01 -0.108 390 2013-05-01 -0.152 391 2013-06-01 -0.197 392 2013-07-01 -0.242 393 2013-08-01 -0.285 394 2013-09-01 -0.326 395 2013-10-01 -0.361 396 2013-11-01 -0.381 397 2013-12-01 -0.389 398 2014-01-01 -0.394 399 2014-02-01 -0.400 400 2014-03-01 -0.399 401 2014-04-01 -0.394 402 2014-05-01 -0.382 403 2014-06-01 -0.369 404 2014-07-01 -0.353 405 2014-08-01 -0.340 406 2014-09-01 -0.328 407 2014-10-01 -0.316 408 2014-11-01 -0.311 409 2014-12-01 -0.312 410 2015-01-01 -0.320 411 2015-02-01 -0.326 412 2015-03-01 -0.333 413 2015-04-01 -0.342 414 2015-05-01 -0.348 415 2015-06-01 -0.351 416 2015-07-01 -0.357 417 2015-08-01 -0.362 418 2015-09-01 -0.370 419 2015-10-01 -0.378 420 2015-11-01 -0.387 421 2015-12-01 -0.398 422 2016-01-01 -0.407 423 2016-02-01 -0.418 424 2016-03-01 -0.433 425 2016-04-01 -0.447 426 2016-05-01 -0.462 427 2016-06-01 -0.475 428 2016-07-01 -0.486 429 2016-08-01 -0.498 430 2016-09-01 -0.509 431 2016-10-01 -0.517 432 2016-11-01 -0.523 433 2016-12-01 -0.522 434 2017-01-01 -0.514 435 2017-02-01 -0.504 436 2017-03-01 -0.494 437 2017-04-01 -0.482 438 2017-05-01 -0.472 439 2017-06-01 -0.464 440 2017-07-01 -0.454 441 2017-08-01 -0.443 442 2017-09-01 -0.432 443 2017-10-01 -0.421 444 2017-11-01 -0.407 445 2017-12-01 -0.394 446 2018-01-01 -0.381 447 2018-02-01 -0.367 448 2018-03-01 -0.353 449 2018-04-01 -0.337 450 2018-05-01 -0.317 451 2018-06-01 -0.297 452 2018-07-01 -0.276 453 2018-08-01 -0.254 454 2018-09-01 -0.230 455 2018-10-01 -0.203 456 2018-11-01 -0.180 457 2018-12-01 -0.163 458 2019-01-01 -0.149 459 2019-02-01 -0.132 460 2019-03-01 -0.113 461 2019-04-01 -0.094 462 2019-05-01 -0.077 463 2019-06-01 -0.064 464 2019-07-01 -0.052 465 2019-08-01 -0.040 466 2019-09-01 -0.030 467 2019-10-01 -0.020 468 2019-11-01 -0.008 469 2019-12-01 0.011 470 2020-01-01 0.036 471 2020-02-01 0.056 472 2020-03-01 0.067 473 2020-04-01 0.066 474 2020-05-01 0.059 475 2020-06-01 0.056 476 2020-07-01 0.057 477 2020-08-01 0.056 478 2020-09-01 0.056 479 2020-10-01 0.053 480 2020-11-01 0.048 481 2020-12-01 0.044 482 2021-01-01 0.044 483 2021-02-01 0.046 484 2021-03-01 0.059 485 2021-04-01 0.081 486 2021-05-01 0.109 487 2021-06-01 0.135 488 2021-07-01 0.164 489 2021-08-01 0.199 490 2021-09-01 0.237 491 2021-10-01 0.281 492 2021-11-01 0.330 493 2021-12-01 0.373 494 2022-01-01 0.410 495 2022-02-01 0.448 496 2022-03-01 0.494 497 2022-04-01 0.536 > > proc.time() user system elapsed 1.09 0.20 1.42