Skip to content

Commit

Permalink
change more occurances of error() to Rf_error()
Browse files Browse the repository at this point in the history
  • Loading branch information
sneumann committed Nov 20, 2024
1 parent f9796eb commit c41bd1d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 22 deletions.
14 changes: 7 additions & 7 deletions src/binners.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ SEXP binYonX(SEXP x, SEXP y, SEXP breaks, SEXP nBins, SEXP binSize,
base_value = REAL(baseValue)[0];

if (from_idx < 0 || to_idx < 0)
error("'fromIdx' and 'toIdx' have to be >= 0!");
Rf_error("'fromIdx' and 'toIdx' have to be >= 0!");
if (from_idx > to_idx)
error("'fromIdx' has to be smaller than 'toIdx'!");
Rf_error("'fromIdx' has to be smaller than 'toIdx'!");
if (to_idx >= LENGTH(x))
error("'toIdx' can not be larger than length(x)!");
Rf_error("'toIdx' can not be larger than length(x)!");

/* Define from_x and to_x */
if (ISNA(REAL(fromX)[0])) {
Expand All @@ -95,12 +95,12 @@ SEXP binYonX(SEXP x, SEXP y, SEXP breaks, SEXP nBins, SEXP binSize,
n_bin = (LENGTH(breaks) - 1);
p_brks = REAL(breaks);
if (n_bin < 1)
error("Not enough breaks defined!");
Rf_error("Not enough breaks defined!");
} else if (INTEGER(nBins)[0] != NA_INTEGER) {
/* Calculating breaks based on the number of bins. */
n_bin = asInteger(nBins);
if (n_bin <= 0)
error("'nBins' must be larger 1!");
Rf_error("'nBins' must be larger 1!");
PROTECT(brks = allocVector(REALSXP, n_bin + 1));
count_protect++;
/* Calculate the breaks */
Expand All @@ -110,7 +110,7 @@ SEXP binYonX(SEXP x, SEXP y, SEXP breaks, SEXP nBins, SEXP binSize,
/* Calculating breaks based on bin size. */
bin_size = REAL(binSize)[0];
if (bin_size < 0)
error("'binSize' has to be > 0!");
Rf_error("'binSize' has to be > 0!");
if (shift_by_half_bin_size > 0) {
from_x = from_x - (bin_size / 2);
to_x = to_x + (bin_size / 2);
Expand Down Expand Up @@ -224,7 +224,7 @@ SEXP binYonX_multi(SEXP x, SEXP y, SEXP breaks, SEXP nBins, SEXP binSize,
SEXP res, from_idx, to_idx, current_res;
int n_subsets, *p_subset_from_idx, *p_subset_to_idx;
if (LENGTH(subsetFromIdx) != LENGTH(subsetToIdx)) {
error("Arguments 'subsetFromIdx' and 'subsetToIdx' have to have the same length!");
Rf_error("Arguments 'subsetFromIdx' and 'subsetToIdx' have to have the same length!");
}
n_subsets = LENGTH(subsetFromIdx);
p_subset_from_idx = INTEGER(subsetFromIdx);
Expand Down
2 changes: 1 addition & 1 deletion src/fastMatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ SEXP fastMatch(SEXP x, SEXP y, SEXP xidx, SEXP yidx, SEXP xolength, SEXP tol) {

struct idxStruct * pidxS = (struct idxStruct *) calloc(nx, sizeof(struct idxStruct));
if (pidxS == NULL)
error("fastMatch/calloc: memory could not be allocated ! (%lu bytes)\n", nx * sizeof(struct idxStruct) );
Rf_error("fastMatch/calloc: memory could not be allocated ! (%lu bytes)\n", nx * sizeof(struct idxStruct) );
for (xi=0;xi < nx;xi++)
pidxS[xi].from = ny+1;

Expand Down
2 changes: 1 addition & 1 deletion src/massifquant/nmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ double gamma_cody(double);
#ifndef MATHLIB_STANDALONE

#include <R_ext/Error.h>
# define MATHLIB_ERROR(fmt,x) error(fmt,x);
# define MATHLIB_ERROR(fmt,x) Rf_error(fmt,x);
# define MATHLIB_WARNING(fmt,x) warning(fmt,x)
# define MATHLIB_WARNING2(fmt,x,x2) warning(fmt,x,x2)
# define MATHLIB_WARNING3(fmt,x,x2,x3) warning(fmt,x,x2,x3)
Expand Down
26 changes: 13 additions & 13 deletions src/mzROI.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ struct mzROIStruct * checkmzROIBufSize(struct mzROIStruct *mzROI, const unsigned

mzROI = (struct mzROIStruct *) realloc(mzROI, newLength * sizeof(struct mzROIStruct));
if (mzROI == NULL)
error("findmzROI/realloc: buffer memory could not be allocated ! (%lu bytes)\n", newLength * sizeof(struct mzROIStruct) );
Rf_error("findmzROI/realloc: buffer memory could not be allocated ! (%lu bytes)\n", newLength * sizeof(struct mzROIStruct) );

mzLength->mzROITotal = newLength;
}
Expand All @@ -99,7 +99,7 @@ struct mzROIStruct * checkmzvalBufSize(struct mzROIStruct *mzval, const unsigned

mzval = (struct mzROIStruct *) realloc(mzval, newLength * sizeof(struct mzROIStruct));
if (mzval == NULL)
error("findmzROI/realloc: buffer memory could not be allocated ! (%lu bytes)\n", newLength * sizeof(struct mzROIStruct));
Rf_error("findmzROI/realloc: buffer memory could not be allocated ! (%lu bytes)\n", newLength * sizeof(struct mzROIStruct));

mzLength->mzvalTotal = newLength;
}
Expand Down Expand Up @@ -202,7 +202,7 @@ struct mzROIStruct * insertpeak(const double fMass, const double fInten,

if (ddiff <= ddev)
{ // match (smaller than defined ppm) -> extend this ROI
if ( (i > hpos) || (i<lpos) ) error("! scan: %d \n",scan);
if ( (i > hpos) || (i<lpos) ) Rf_error("! scan: %d \n",scan);
wasfound = TRUE;
//recursive m/z mean update
mzval[i].mz = ((mzval[i].length * mzval[i].mz) + fMass) / (mzval[i].length + 1);
Expand Down Expand Up @@ -311,7 +311,7 @@ int i,p,del=0;
}
if (entries > ctScan) {
#ifdef DEBUG
error("Warning : entries > ctScan (is this centroid data ?) i: %d m: %3.4f %d entries, lastscan %d (ctScan=%d)\n",i,mzval[i].mz,mzval[i].length,lastscan,ctScan);
Rf_error("Warning : entries > ctScan (is this centroid data ?) i: %d m: %3.4f %d entries, lastscan %d (ctScan=%d)\n",i,mzval[i].mz,mzval[i].length,lastscan,ctScan);
#endif
(*scerr)++;
}
Expand All @@ -328,7 +328,7 @@ int i,p,del=0;
p=0;
struct mzROIStruct * tmp = (struct mzROIStruct *) calloc(mzLength->mzval - del, sizeof(struct mzROIStruct));
if (tmp == NULL)
error("findmzROI/cleanup: buffer memory could not be allocated ! (%lu bytes)\n", (mzLength->mzval - del) * sizeof(struct mzROIStruct));
Rf_error("findmzROI/cleanup: buffer memory could not be allocated ! (%lu bytes)\n", (mzLength->mzval - del) * sizeof(struct mzROIStruct));
for (i=0; i < mzLength->mzval; i++) {
if (mzval[i].deleteMe == FALSE) {
tmp[p].mz = mzval[i].mz;
Expand Down Expand Up @@ -379,7 +379,7 @@ struct scanBuf * getScan(int scan, double *pmz, double *pintensity, int *pscanin
scanbuf->thisScan= (struct scanStruct *) calloc(N, sizeof(struct scanStruct));
// scanbuf->thisScan= (struct scanStruct *) malloc(N * sizeof(struct scanStruct));
if (scanbuf->thisScan == NULL)
error("findmzROI/getThisScan: Memory could not be allocated!\n");
Rf_error("findmzROI/getThisScan: Memory could not be allocated!\n");

scanbuf->thisScanLength=N;

Expand Down Expand Up @@ -411,7 +411,7 @@ struct scanBuf * getScan(int scan, double *pmz, double *pintensity, int *pscanin
if (N > 0) {
scanbuf->nextScan= (double *) calloc(N, sizeof(double));
if (scanbuf->nextScan == NULL)
error("findmzROI/getNextScan: Memory could not be allocated!\n");
Rf_error("findmzROI/getNextScan: Memory could not be allocated!\n");
scanbuf->nextScanLength=N;

for (idx=idx1;idx <= idx2; idx++)
Expand Down Expand Up @@ -463,7 +463,7 @@ SEXP getEIC(SEXP mz, SEXP intensity, SEXP scanindex, SEXP mzrange, SEXP scanrang
scanrangeFrom = INTEGER(scanrange)[0];
scanrangeTo = INTEGER(scanrange)[1];
if ((scanrangeFrom < firstScan) || (scanrangeFrom > ilastScan) || (scanrangeTo < firstScan) || (scanrangeTo > ilastScan))
error("Error in scanrange \n");
Rf_error("Error in scanrange \n");
char *names[2] = {"scan", "intensity"};
PROTECT(list_names = allocVector(STRSXP, 2));
for(i = 0; i < 2; i++)
Expand Down Expand Up @@ -508,7 +508,7 @@ SEXP getMZ(SEXP mz, SEXP intensity, SEXP scanindex, SEXP mzrange, SEXP scanrange
scanrangeFrom = INTEGER(scanrange)[0];
scanrangeTo = INTEGER(scanrange)[1];
if ((scanrangeFrom < firstScan) || (scanrangeFrom > ilastScan) || (scanrangeTo < firstScan) || (scanrangeTo > ilastScan))
error("Error in scanrange \n");
Rf_error("Error in scanrange \n");

buflength = scanrangeTo - scanrangeFrom +1;
PROTECT(res = NEW_NUMERIC(buflength));
Expand Down Expand Up @@ -563,7 +563,7 @@ SEXP getWeightedMZ(SEXP mz, SEXP intensity, SEXP scanindex, SEXP mzrange,
scanrangeTo = INTEGER(scanrange)[1];
if ((scanrangeFrom < firstScan) || (scanrangeFrom > ilastScan) ||
(scanrangeTo < firstScan) || (scanrangeTo > ilastScan))
error("Error in scanrange \n");
Rf_error("Error in scanrange \n");

buflength = scanrangeTo - scanrangeFrom +1;
PROTECT(res = NEW_NUMERIC(buflength));
Expand Down Expand Up @@ -626,11 +626,11 @@ SEXP findmzROI(SEXP mz, SEXP intensity, SEXP scanindex, SEXP mzrange,

struct mzROIStruct * mzROI = (struct mzROIStruct *) calloc(ROI_INIT_LENGTH, sizeof(struct mzROIStruct));
if (mzROI == NULL)
error("findmzROI/calloc: buffer memory could not be allocated ! (%lu bytes)\n",ROI_INIT_LENGTH * sizeof(struct mzROIStruct) );
Rf_error("findmzROI/calloc: buffer memory could not be allocated ! (%lu bytes)\n",ROI_INIT_LENGTH * sizeof(struct mzROIStruct) );

struct mzROIStruct * mzval = (struct mzROIStruct *) calloc(MZVAL_INIT_LENGTH, sizeof(struct mzROIStruct));
if (mzval == NULL)
error("findmzROI/calloc: buffer memory could not be allocated ! (%lu bytes)\n",MZVAL_INIT_LENGTH * sizeof(struct mzROIStruct) );
Rf_error("findmzROI/calloc: buffer memory could not be allocated ! (%lu bytes)\n",MZVAL_INIT_LENGTH * sizeof(struct mzROIStruct) );

mzLength.mzvalTotal = MZVAL_INIT_LENGTH;
mzLength.mzROITotal = ROI_INIT_LENGTH;
Expand Down Expand Up @@ -678,7 +678,7 @@ SEXP findmzROI(SEXP mz, SEXP intensity, SEXP scanindex, SEXP mzrange,
fInten = scanbuf->thisScan[p].intensity;

if (fMass < lastMass)
error("m/z sort assumption violated ! (scan %d, p %d, current %2.4f (I=%2.2f), last %2.4f) \n",ctScan,p,fMass,fInten,lastMass);
Rf_error("m/z sort assumption violated ! (scan %d, p %d, current %2.4f (I=%2.2f), last %2.4f) \n",ctScan,p,fMass,fInten,lastMass);
lastMass = fMass;

if (fInten > inoise)
Expand Down

0 comments on commit c41bd1d

Please sign in to comment.