Skip to content

Commit

Permalink
fix some C++ code flagged by CRAN warnings (#1386)
Browse files Browse the repository at this point in the history
  • Loading branch information
perrydv authored Jan 11, 2024
1 parent cdb1329 commit 7e6170b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions packages/nimble/inst/CppCode/RcppUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ vector<int> SEXP_2_vectorInt( SEXP Sn, int offset ) {

int SEXP_2_int(SEXP Sn, int i ) {
if(!(Rf_isNumeric(Sn) || Rf_isLogical(Sn))) PRINTF("Error: SEXP_2_int called for SEXP that is not numeric or logical\n");
if(LENGTH(Sn) <= i) PRINTF("Error: SEXP_2_int called for element %i% >= length of %i.\n", i, LENGTH(Sn));
if(LENGTH(Sn) <= i) PRINTF("Error: SEXP_2_int called for element %i% which is beyond the length of %i.\n", i, LENGTH(Sn));
if(Rf_isInteger(Sn) || Rf_isLogical(Sn)) {
if(Rf_isInteger(Sn))
return(INTEGER(Sn)[i]);
Expand Down Expand Up @@ -270,7 +270,7 @@ SEXP bool_2_SEXP(bool ind){

bool SEXP_2_bool(SEXP Sn, int i) {
if(!(Rf_isNumeric(Sn) || Rf_isLogical(Sn))) PRINTF("Error: SEXP_2_bool called for SEXP that is not numeric or logical\n");
if(LENGTH(Sn) <= i) PRINTF("Error: SEXP_2_bool called for element %i% >= length of %i.\n", i, LENGTH(Sn));
if(LENGTH(Sn) <= i) PRINTF("Error: SEXP_2_bool called for element %i% which is beyond the length of %i.\n", i, LENGTH(Sn));
if(Rf_isLogical(Sn)) {
return(static_cast<bool>(LOGICAL(Sn)[i]));
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/nimble/inst/CppCode/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ bool decide(double lMHr) { // simple function accept or reject based on log Metr
return(false);
}

void nimStop(string msg) {NIMERROR(msg.c_str());}
void nimStop() {NIMERROR("");}
void nimStop(string msg) {NIMERROR("%s", msg.c_str());}
void nimStop() {NIMERROR("Error. Exiting from compiled execution.");}

bool nimNot(bool x) {return(!x);}

Expand Down
8 changes: 4 additions & 4 deletions packages/nimble/inst/CppCode/eigenUsingClasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ template<>
void SEXP_2_NimArr<1>(SEXP Sn, NimArr<1, double> &ans) {
NIM_ASSERT2(Rf_isNumeric(Sn) || Rf_isLogical(Sn),
"SEXP_2_NimArr<1, double> called for SEXP that is not a numeric or logical: actual type %s\n",
Rf_type2str(TYPEOF(Sn)));
Rf_type2char(TYPEOF(Sn)));
int nn = LENGTH(Sn);
NIM_ASSERT1(ans.size() == 0, "trying to reset a NimArr that was already sized\n");
ans.setSize(nn);
Expand All @@ -39,7 +39,7 @@ void SEXP_2_NimArr<1>(SEXP Sn, NimArr<1, double> &ans) {
} else {
NIM_ASSERT2(Rf_isInteger(Sn) || Rf_isLogical(Sn),
"could not handle input of type %s to SEXP_2_NimArr<1, double>\n",
Rf_type2str(TYPEOF(Sn)));
Rf_type2char(TYPEOF(Sn)));
int *iSn = Rf_isInteger(Sn) ? INTEGER(Sn) : LOGICAL(Sn);
for(int i = 0; i < nn; ++i) {
ans(i) = static_cast<double>(iSn[i]);
Expand All @@ -52,7 +52,7 @@ template<>
void SEXP_2_NimArr<1>(SEXP Sn, NimArr<1, int> &ans) {
NIM_ASSERT2(Rf_isNumeric(Sn) || Rf_isLogical(Sn),
"SEXP_2_NimArr<1, int> called for SEXP that is not a numeric or logical: actual type %s\n",
Rf_type2str(TYPEOF(Sn)));
Rf_type2char(TYPEOF(Sn)));
int nn = LENGTH(Sn);
NIM_ASSERT1(ans.size() == 0, "trying to reset a NimArr that was already sized\n");
ans.setSize(nn);
Expand All @@ -61,7 +61,7 @@ void SEXP_2_NimArr<1>(SEXP Sn, NimArr<1, int> &ans) {
} else {
NIM_ASSERT2(Rf_isInteger(Sn) || Rf_isLogical(Sn),
"could not handle input of type %s to SEXP_2_NimArr<1, int>\n",
Rf_type2str(TYPEOF(Sn)));
Rf_type2char(TYPEOF(Sn)));
int *iSn = Rf_isInteger(Sn) ? INTEGER(Sn) : LOGICAL(Sn);
for(int i = 0; i < nn; ++i) {
ans(i) = static_cast<double>(iSn[i]);
Expand Down
14 changes: 7 additions & 7 deletions packages/nimble/inst/include/nimble/RcppNimbleUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,11 @@ template<int ndim>
void SEXP_2_NimArr(SEXP Sn, NimArr<ndim, double> &ans) {
NIM_ASSERT3(Rf_isNumeric(Sn) || Rf_isLogical(Sn),
"SEXP_2_NimArr<%d, double> called for SEXP that is not a numeric or logical: actual type %s\n",
ndim, Rf_type2str(TYPEOF(Sn)));
ndim, Rf_type2char(TYPEOF(Sn)));
vector<int> inputDims(getSEXPdims(Sn));
NIM_ASSERT4(inputDims.size() == ndim,
"Wrong number of input dimensions in SEXP_2_NimArr<%d, double> called for SEXP that is not a numeric: expected %d, actual %d\n",
ndim, ndim, inputDims.size());
ndim, ndim, static_cast<int>(inputDims.size()));
// NIM_ASSERT(ans.size() == 0, "trying to reset a NimArr that was already sized\n");
ans.setSize(inputDims);
int nn = LENGTH(Sn);
Expand All @@ -252,7 +252,7 @@ void SEXP_2_NimArr(SEXP Sn, NimArr<ndim, double> &ans) {
} else {
NIM_ASSERT3(Rf_isInteger(Sn) || Rf_isLogical(Sn),
"could not handle input of type %s to SEXP_2_NimArr<%d, double>\n",
Rf_type2str(TYPEOF(Sn)), ndim);
Rf_type2char(TYPEOF(Sn)), ndim);
int *iSn = Rf_isInteger(Sn) ? INTEGER(Sn) : LOGICAL(Sn);
std::copy(iSn, iSn + nn, ans.getPtr()); //v);
}
Expand All @@ -263,7 +263,7 @@ template<int ndim>
void SEXP_2_NimArr(SEXP Sn, NimArr<ndim, int> &ans) {
NIM_ASSERT3(Rf_isNumeric(Sn) || Rf_isLogical(Sn),
"SEXP_2_NimArr<%d, int> called for SEXP that is not a numeric or logical: actual type %s\n",
ndim, Rf_type2str(TYPEOF(Sn)));
ndim, Rf_type2char(TYPEOF(Sn)));
vector<int> inputDims(getSEXPdims(Sn));
NIM_ASSERT4(inputDims.size() == ndim,
"Wrong number of input dimensions in SEXP_2_NimArr<%d, int> called for SEXP that is not a numeric: expected %d, actual %d\n",
Expand All @@ -276,7 +276,7 @@ void SEXP_2_NimArr(SEXP Sn, NimArr<ndim, int> &ans) {
} else {
NIM_ASSERT3(Rf_isInteger(Sn) || Rf_isLogical(Sn),
"could not handle input type %s to SEXP_2_NimArr<%d, int>\n",
Rf_type2str(TYPEOF(Sn)), ndim);
Rf_type2char(TYPEOF(Sn)), ndim);
int *iSn = Rf_isInteger(Sn) ? INTEGER(Sn) : LOGICAL(Sn);
std::copy(iSn, iSn + nn, ans.getPtr()); //v);
}
Expand All @@ -286,7 +286,7 @@ template<int ndim>
void SEXP_2_NimArr(SEXP Sn, NimArr<ndim, bool> &ans) {
NIM_ASSERT3(Rf_isNumeric(Sn) || Rf_isLogical(Sn),
"SEXP_2_NimArr<%d, bool> called for SEXP that is not a numeric or logical: actual type %s\n",
ndim, Rf_type2str(TYPEOF(Sn)));
ndim, Rf_type2char(TYPEOF(Sn)));
vector<int> inputDims(getSEXPdims(Sn));
NIM_ASSERT4(inputDims.size() == ndim,
"Wrong number of input dimensions in SEXP_2_NimArr<%d, bool> called for SEXP that is not a numeric: expected %d, actual %d\n",
Expand All @@ -299,7 +299,7 @@ void SEXP_2_NimArr(SEXP Sn, NimArr<ndim, bool> &ans) {
} else {
NIM_ASSERT3(Rf_isInteger(Sn) || Rf_isLogical(Sn),
"could not handle input type %s to SEXP_2_NimArr<%d, bool>\n",
Rf_type2str(TYPEOF(Sn)), ndim);
Rf_type2char(TYPEOF(Sn)), ndim);
int *iSn = Rf_isInteger(Sn) ? INTEGER(Sn) : LOGICAL(Sn);
std::copy(iSn, iSn + nn, ans.getPtr()); //v);
}
Expand Down

0 comments on commit 7e6170b

Please sign in to comment.