From c41bd1d93f2c38d0a17722616d028f3bc715da71 Mon Sep 17 00:00:00 2001 From: Steffen Neumann Date: Wed, 20 Nov 2024 18:13:56 +0100 Subject: [PATCH] change more occurances of error() to Rf_error() --- src/binners.c | 14 +++++++------- src/fastMatch.c | 2 +- src/massifquant/nmath.h | 2 +- src/mzROI.c | 26 +++++++++++++------------- 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/binners.c b/src/binners.c index f97136310..58a6948d0 100644 --- a/src/binners.c +++ b/src/binners.c @@ -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])) { @@ -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 */ @@ -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); @@ -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); diff --git a/src/fastMatch.c b/src/fastMatch.c index 667583ecc..232e89208 100644 --- a/src/fastMatch.c +++ b/src/fastMatch.c @@ -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; diff --git a/src/massifquant/nmath.h b/src/massifquant/nmath.h index 114232786..9b7a94243 100644 --- a/src/massifquant/nmath.h +++ b/src/massifquant/nmath.h @@ -46,7 +46,7 @@ double gamma_cody(double); #ifndef MATHLIB_STANDALONE #include -# 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) diff --git a/src/mzROI.c b/src/mzROI.c index 19333b469..5474ccd79 100644 --- a/src/mzROI.c +++ b/src/mzROI.c @@ -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; } @@ -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; } @@ -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 hpos) || (i 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)++; } @@ -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; @@ -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; @@ -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++) @@ -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++) @@ -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)); @@ -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)); @@ -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; @@ -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)