Skip to content

Commit

Permalink
Merge pull request #273 from Rblp/bugfix/date-vector
Browse files Browse the repository at this point in the history
Bugfix/date vector
  • Loading branch information
eddelbuettel committed Jul 24, 2018
2 parents 8134548 + 6e52cec commit 8082a77
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 14 deletions.
5 changes: 2 additions & 3 deletions src/bds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ void populateDfRowBDS(SEXP ans, R_len_t row_index, Element& e) {
Rcpp::stop("Unsupported datatype: BLPAPI_DATATYPE_BYTEARRAY.");
break;
case BLPAPI_DATATYPE_DATE:
INTEGER(ans)[row_index] = bbgDateToRDate(e.getValueAsDatetime());
REAL(ans)[row_index] = bbgDateToRDate(e.getValueAsDatetime());
break;
case BLPAPI_DATATYPE_TIME:
//FIXME: separate out time later
Expand Down Expand Up @@ -132,8 +132,7 @@ SEXP allocateDataFrameColumn(int fieldT, size_t n) {
Rcpp::stop("Unsupported datatype: BLPAPI_DATATYPE_BYTEARRAY.");
break;
case BLPAPI_DATATYPE_DATE:
ans = Rcpp::IntegerVector(n, NA_INTEGER);
addDateClass(ans);
ans = Rcpp::DateVector(n);
break;
case BLPAPI_DATATYPE_TIME:
//FIXME: separate out time later
Expand Down
12 changes: 2 additions & 10 deletions src/blpapi_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,13 +135,6 @@ const double bbgDatetimeToUTC(const BloombergLP::blpapi::Datetime& dt) {
return x;
}

void addDateClass(SEXP x) {
// create and add dates class to dates object
// cf Rcpp's inst/include/Rcpp/date_datetime/newDateVector.h
Rcpp::Shield<SEXP> dateclass(Rf_mkString("Date"));
Rf_setAttrib(x, R_ClassSymbol, dateclass);
}

void addPosixClass(SEXP x) {
// create and add dates class to dates object
// cf Rcpp's inst/include/Rcpp/date_datetime/newDatetimeVector.h
Expand Down Expand Up @@ -242,7 +235,7 @@ void populateDfRow(SEXP ans, R_len_t row_index, const Element& e, RblpapiT rblpa
REAL(ans)[row_index] = e.getValueAsFloat64(); break;
case RblpapiT::Date:
// handle the case of BBG passing down dates as double in YYYYMMDD format
INTEGER(ans)[row_index] = e.datatype()==BLPAPI_DATATYPE_FLOAT32 || e.datatype()==BLPAPI_DATATYPE_FLOAT64 ?
REAL(ans)[row_index] = e.datatype()==BLPAPI_DATATYPE_FLOAT32 || e.datatype()==BLPAPI_DATATYPE_FLOAT64 ?
bbgDateToRDate(e.getValueAsFloat64()) :
bbgDateToRDate(e.getValueAsDatetime());
break;
Expand Down Expand Up @@ -335,8 +328,7 @@ SEXP allocateDataFrameColumn(RblpapiT rblpapitype, const size_t n) {
ans = Rcpp::NumericVector(n, NA_REAL);
break;
case RblpapiT::Date:
ans = Rcpp::IntegerVector(n, NA_INTEGER);
addDateClass(ans);
ans = Rcpp::DateVector(n);
break;
case RblpapiT::Datetime:
// FIXME: string for datetime ?
Expand Down
1 change: 0 additions & 1 deletion src/blpapi_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ void createStandardRequest(BloombergLP::blpapi::Request& request,const std::vect
void sendRequestWithIdentity(BloombergLP::blpapi::Session* session, BloombergLP::blpapi::Request& request, SEXP identity_);

void populateDfRow(SEXP ans, R_len_t row_index, const BloombergLP::blpapi::Element& e, RblpapiT rblpapitype);
void addDateClass(SEXP x);
void addPosixClass(SEXP x);

Rcpp::NumericVector createPOSIXtVector(const std::vector<double> & ticks, const std::string tz="UTC");
Expand Down

0 comments on commit 8082a77

Please sign in to comment.