Skip to content

Commit 769ab8c

Browse files
authored
Merge pull request #573 from RcppCore/bugfix/newdatetime_tests
updated one unit test for new datetime vectors
2 parents 3fab6a2 + 2119978 commit 769ab8c

File tree

4 files changed

+40
-8
lines changed

4 files changed

+40
-8
lines changed

ChangeLog

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2016-10-30 Dirk Eddelbuettel <[email protected]>
2+
3+
* src/api.cpp: New capabilities field for new date(time) vectors
4+
* inst/unitTests/runit.Date.R (test.DatetimeVector.ctor): Differentiate
5+
in test as case of 'Inf' is handling differently by new and old datetime
6+
classes (and passed through as is by new ones which is better)
7+
* inst/unitTests/runit.InternalFunctionCPP11.R: Small cosmetic edit
8+
19
2016-10-24 Qiang Kou <[email protected]>
210

311
* inst/include/Rcpp/sugar/Range.h : fix range sugar ambiguity

inst/NEWS.Rd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
\item Changes in Rcpp unit tests
2525
\itemize{
2626
\item A test for expression vectors was corrected.
27+
\item The constructor test for datetime vectors reflects the new classes
28+
which treats Inf correctly (and still as a non-finite value)
2729
}
2830
\item Updated Date and Datetime vector classes:
2931
\itemize{
@@ -35,6 +37,7 @@
3537
\item By defining \code{RCPP_NEW_DATE_DATETIME_VECTORS} the new classes
3638
can activated. We intend to make the new classes the default no sooner
3739
than twelve months from this release.
40+
\item The \code{capabilities()} function can also be tested for this feature
3841
}
3942
}
4043
}

inst/unitTests/runit.Date.R

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env r
22
# -*- mode: R; tab-width: 4; -*-
33
#
4-
# Copyright (C) 2010 - 2013 Dirk Eddelbuettel and Romain Francois
4+
# Copyright (C) 2010 - 2016 Dirk Eddelbuettel and Romain Francois
55
#
66
# This file is part of Rcpp.
77
#
@@ -163,9 +163,23 @@ if (.runThisTest) {
163163
fun <- DatetimeVector_ctor
164164
now <- Sys.time()
165165
checkEquals(fun(now + (0:4)*60), now+(0:4)*60, msg = "Datetime.ctor.sequence")
166-
vec <- c(now, NA, NaN, Inf, now+2.345)
167-
posixtNA <- as.POSIXct(NA, origin="1970-01-01")
168-
checkEquals(fun(vec), c(now, rep(posixtNA, 3), now+2.345), msg = "Datetime.ctor.set")
166+
if (Rcpp:::capabilities()[["new date(time) vectors"]]) {
167+
vec <- c(now, NA, NaN, now+2.345)
168+
posixtNA <- as.POSIXct(NA, origin="1970-01-01")
169+
checkEquals(fun(vec), c(now, rep(posixtNA, 2), now+2.345), msg = "Datetime.ctor.NA.NaN.set")
170+
vec <- c(now, -Inf, Inf, now+2.345)
171+
checkEquals(sum(is.finite(fun(vec))), 2, msg = "Datetime.ctor.Inf.finite.set")
172+
checkEquals(sum(is.infinite(fun(vec))), 2, msg = "Datetime.ctor.Inf.notfinite.set")
173+
vec <- c(now, NA, NaN, Inf, now+2.345)
174+
posixtNA <- as.POSIXct(NA, origin="1970-01-01")
175+
posixtInf <- as.POSIXct(Inf, origin="1970-01-01")
176+
checkEquals(fun(vec), c(now, rep(posixtNA, 2), posixtInf, now+2.345),
177+
msg = "Datetime.ctor.NA.NaN.Inf.set")
178+
} else {
179+
vec <- c(now, NA, NaN, Inf, now+2.345)
180+
posixtNA <- as.POSIXct(NA, origin="1970-01-01")
181+
checkEquals(fun(vec), c(now, rep(posixtNA, 3), now+2.345), msg = "Datetime.ctor.NA.NaN.Inf.set")
182+
}
169183
}
170184

171185
}

src/api.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*-
2-
// jedit: :folding=explicit:
32
//
43
// api.cpp: Rcpp R/C++ interface class library -- Rcpp api
54
//
6-
// Copyright (C) 2012 - 2015 Dirk Eddelbuettel and Romain Francois
5+
// Copyright (C) 2012 - 2016 Dirk Eddelbuettel and Romain Francois
76
//
87
// This file is part of Rcpp.
98
//
@@ -155,8 +154,8 @@ SEXP as_character_externalptr(SEXP xp) {
155154

156155
// [[Rcpp::internal]]
157156
SEXP rcpp_capabilities() {
158-
Shield<SEXP> cap(Rf_allocVector(LGLSXP, 12));
159-
Shield<SEXP> names(Rf_allocVector(STRSXP, 12));
157+
Shield<SEXP> cap(Rf_allocVector(LGLSXP, 13));
158+
Shield<SEXP> names(Rf_allocVector(STRSXP, 13));
160159
#ifdef HAS_VARIADIC_TEMPLATES
161160
LOGICAL(cap)[0] = TRUE;
162161
#else
@@ -216,6 +215,13 @@ SEXP rcpp_capabilities() {
216215
LOGICAL(cap)[11] = FALSE;
217216
#endif
218217

218+
#ifdef RCPP_NEW_DATE_DATETIME_VECTORS
219+
LOGICAL(cap)[12] = TRUE;
220+
#else
221+
LOGICAL(cap)[12] = FALSE;
222+
#endif
223+
224+
219225
SET_STRING_ELT(names, 0, Rf_mkChar("variadic templates"));
220226
SET_STRING_ELT(names, 1, Rf_mkChar("initializer lists"));
221227
SET_STRING_ELT(names, 2, Rf_mkChar("exception handling"));
@@ -228,6 +234,7 @@ SEXP rcpp_capabilities() {
228234
SET_STRING_ELT(names, 9, Rf_mkChar("C++0x unordered maps"));
229235
SET_STRING_ELT(names, 10, Rf_mkChar("C++0x unordered sets"));
230236
SET_STRING_ELT(names, 11, Rf_mkChar("Full C++11 support"));
237+
SET_STRING_ELT(names, 12, Rf_mkChar("new date(time) vectors"));
231238
Rf_setAttrib(cap, R_NamesSymbol, names);
232239
return cap;
233240
}

0 commit comments

Comments
 (0)