Skip to content

Commit eb2736f

Browse files
committed
consider empty vectors in min() and max() (fixes #883)
1 parent e0f04a8 commit eb2736f

File tree

4 files changed

+35
-15
lines changed

4 files changed

+35
-15
lines changed

ChangeLog

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
2018-07-20 Dirk Eddelbuettel <[email protected]>
2+
3+
* inst/include/Rcpp/sugar/functions/max.h (Rcpp): Also consider case
4+
of an empty vector
5+
* inst/include/Rcpp/sugar/functions/min.h (Rcpp): Idem
6+
7+
2018-07-19 Jack Wasey <[email protected]>
8+
9+
* inst/include/Rcpp/r_cast.h: Error and abort if debugging for STRSXP
10+
111
2018-07-12 Dirk Eddelbuettel <[email protected]>
212

313
* DESCRIPTION (Version, Date): Roll minor version

inst/NEWS.Rd

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
\item Next \code{eval} codes now properly unwind (Lionel in the large
1515
and careful \ghpr{859} fixing \ghit{807}).
1616
\item In debugging mode, more type information is shown on
17-
\code{abort()} (Jack Waseyin \ghpr{860} fixing \ghit{857}).
17+
\code{abort()} (Jack Waseyin \ghpr{860} and \ghpr{882} fixing
18+
\ghit{857}).
1819
\item A new class was added which allow suspension of the RNG
1920
synchronisation to address an issue seen in \CRANpkg{RcppDE}
2021
(Kevin in \ghpr{862}).
@@ -30,7 +31,8 @@
3031
\item The \code{Rcpp::unwindProtect()} function extracts the
3132
unwinding from the \code{Rcpp_fast_eval()} function and makes it
3233
more generally available. (Lionel in \ghpr{873} and \ghpr{877}).
33-
\item The \code{tm_gmtoff} part is skipped on AIX too (\ghpr{876}).
34+
\item The \code{tm_gmtoff} part is skipped on AIX too
35+
(\ghpr{876}).
3436
}
3537
\item Changes in Rcpp Attributes:
3638
\itemize{
@@ -41,6 +43,11 @@
4143
the \code{RcppExports} files are more stable across locales (Jack
4244
Wasey in \ghpr{878}).
4345
}
46+
\item Changes in Rcpp Sugar:
47+
\itemize{
48+
\item The sugar functions \code{min} and \code{max} now recognise
49+
empty vectors (Dirk in \ghpr{884} fixing \ghit{883}).
50+
}
4451
}
4552
}
4653

inst/include/Rcpp/sugar/functions/max.h

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
2-
//
1+
32
// max.h: Rcpp R/C++ interface class library -- max
43
//
5-
// Copyright (C) 2012 - 2013 Dirk Eddelbuettel and Romain Francois
4+
// Copyright (C) 2012 - 2018 Dirk Eddelbuettel and Romain Francois
65
//
76
// This file is part of Rcpp.
87
//
@@ -33,11 +32,12 @@ namespace sugar{
3332
Max( const T& obj_) : obj(obj_) {}
3433

3534
operator STORAGE() const {
35+
R_xlen_t n = obj.size();
36+
if (n == 0) return(static_cast<STORAGE>(R_NegInf));
37+
3638
STORAGE max, current ;
3739
max = obj[0] ;
3840
if( Rcpp::traits::is_na<RTYPE>( max ) ) return max ;
39-
40-
R_xlen_t n = obj.size() ;
4141
for( R_xlen_t i=1; i<n; i++){
4242
current = obj[i] ;
4343
if( Rcpp::traits::is_na<RTYPE>( current ) ) return current;
@@ -59,10 +59,11 @@ namespace sugar{
5959
Max( const T& obj_) : obj(obj_) {}
6060

6161
operator STORAGE() const {
62+
R_xlen_t n = obj.size();
63+
if (n == 0) return(static_cast<STORAGE>(R_NegInf));
64+
6265
STORAGE max, current ;
6366
max = obj[0] ;
64-
65-
R_xlen_t n = obj.size() ;
6667
for( R_xlen_t i=1; i<n; i++){
6768
current = obj[i] ;
6869
if( current > max ) max = current ;

inst/include/Rcpp/sugar/functions/min.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*-
2-
//
1+
32
// Min.h: Rcpp R/C++ interface class library -- min
43
//
5-
// Copyright (C) 2012 - 2013 Dirk Eddelbuettel and Romain Francois
4+
// Copyright (C) 2012 - 2018 Dirk Eddelbuettel and Romain Francois
65
//
76
// This file is part of Rcpp.
87
//
@@ -33,11 +32,13 @@ namespace sugar{
3332
Min( const T& obj_) : obj(obj_) {}
3433

3534
operator STORAGE() const {
35+
R_xlen_t n = obj.size();
36+
if (n == 0) return(static_cast<STORAGE>(R_PosInf));
37+
3638
STORAGE min, current ;
3739
min = obj[0] ;
3840
if( Rcpp::traits::is_na<RTYPE>( min ) ) return min ;
3941

40-
R_xlen_t n = obj.size() ;
4142
for( R_xlen_t i=1; i<n; i++){
4243
current = obj[i] ;
4344
if( Rcpp::traits::is_na<RTYPE>( current ) ) return current;
@@ -58,10 +59,11 @@ namespace sugar{
5859
Min( const T& obj_) : obj(obj_) {}
5960

6061
operator STORAGE() const {
62+
R_xlen_t n = obj.size();
63+
if (n == 0) return(static_cast<STORAGE>(R_PosInf));
64+
6165
STORAGE min, current ;
6266
min = obj[0] ;
63-
64-
R_xlen_t n = obj.size() ;
6567
for( R_xlen_t i=1; i<n; i++){
6668
current = obj[i] ;
6769
if( current < min ) min = current ;

0 commit comments

Comments
 (0)