Skip to content

Commit 074cf83

Browse files
authored
Merge pull request #780 from sneumann/fix/issue778
Fix/issue778 using Rf_error()
2 parents d3e8acf + 56a4224 commit 074cf83

File tree

10 files changed

+51
-45
lines changed

10 files changed

+51
-45
lines changed

.editorconfig

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ root = true
66
charset = utf-8
77
end_of_line = lf
88
trim_trailing_whitespace = true
9-
insert_final_newline = false
9+
insert_final_newline = true
1010

1111
[*.R]
1212
indent_style = space
@@ -18,4 +18,4 @@ indent_style = tab
1818

1919
[.travis.yml]
2020
indent_style = space
21-
indent_size = 2
21+
indent_size = 2

.github/workflows/check-bioc.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ jobs:
5454
matrix:
5555
config:
5656
- { os: ubuntu-latest, r: 'devel', bioc: 'devel', cont: "bioconductor/bioconductor_docker:devel", rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest" }
57-
- { os: macOS-latest, r: '4.4', bioc: 'devel'}
58-
- { os: windows-latest, r: '4.4', bioc: 'devel'}
57+
- { os: macOS-latest, r: '4.4', bioc: '3.20'}
58+
- { os: windows-latest, r: '4.4', bioc: '3.20'}
5959
env:
6060
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
6161
RSPM: ${{ matrix.config.rspm }}

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: xcms
2-
Version: 4.5.0
2+
Version: 4.5.1
33
Title: LC-MS and GC-MS Data Analysis
44
Description: Framework for processing and visualization of chromatographically
55
separated and single-spectra mass spectral data. Imports from AIA/ANDI NetCDF,

NEWS.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# xcms 4.5.1
2+
3+
## Changes in version 4.5.1
4+
5+
- Fix compile errors with R-4.5
6+
17
# xcms 4.3
28

39
## Changes in version 4.3.4

src/binners.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,11 @@ SEXP binYonX(SEXP x, SEXP y, SEXP breaks, SEXP nBins, SEXP binSize,
7272
base_value = REAL(baseValue)[0];
7373

7474
if (from_idx < 0 || to_idx < 0)
75-
error("'fromIdx' and 'toIdx' have to be >= 0!");
75+
Rf_error("'fromIdx' and 'toIdx' have to be >= 0!");
7676
if (from_idx > to_idx)
77-
error("'fromIdx' has to be smaller than 'toIdx'!");
77+
Rf_error("'fromIdx' has to be smaller than 'toIdx'!");
7878
if (to_idx >= LENGTH(x))
79-
error("'toIdx' can not be larger than length(x)!");
79+
Rf_error("'toIdx' can not be larger than length(x)!");
8080

8181
/* Define from_x and to_x */
8282
if (ISNA(REAL(fromX)[0])) {
@@ -95,12 +95,12 @@ SEXP binYonX(SEXP x, SEXP y, SEXP breaks, SEXP nBins, SEXP binSize,
9595
n_bin = (LENGTH(breaks) - 1);
9696
p_brks = REAL(breaks);
9797
if (n_bin < 1)
98-
error("Not enough breaks defined!");
98+
Rf_error("Not enough breaks defined!");
9999
} else if (INTEGER(nBins)[0] != NA_INTEGER) {
100100
/* Calculating breaks based on the number of bins. */
101101
n_bin = asInteger(nBins);
102102
if (n_bin <= 0)
103-
error("'nBins' must be larger 1!");
103+
Rf_error("'nBins' must be larger 1!");
104104
PROTECT(brks = allocVector(REALSXP, n_bin + 1));
105105
count_protect++;
106106
/* Calculate the breaks */
@@ -110,7 +110,7 @@ SEXP binYonX(SEXP x, SEXP y, SEXP breaks, SEXP nBins, SEXP binSize,
110110
/* Calculating breaks based on bin size. */
111111
bin_size = REAL(binSize)[0];
112112
if (bin_size < 0)
113-
error("'binSize' has to be > 0!");
113+
Rf_error("'binSize' has to be > 0!");
114114
if (shift_by_half_bin_size > 0) {
115115
from_x = from_x - (bin_size / 2);
116116
to_x = to_x + (bin_size / 2);
@@ -224,7 +224,7 @@ SEXP binYonX_multi(SEXP x, SEXP y, SEXP breaks, SEXP nBins, SEXP binSize,
224224
SEXP res, from_idx, to_idx, current_res;
225225
int n_subsets, *p_subset_from_idx, *p_subset_to_idx;
226226
if (LENGTH(subsetFromIdx) != LENGTH(subsetToIdx)) {
227-
error("Arguments 'subsetFromIdx' and 'subsetToIdx' have to have the same length!");
227+
Rf_error("Arguments 'subsetFromIdx' and 'subsetToIdx' have to have the same length!");
228228
}
229229
n_subsets = LENGTH(subsetFromIdx);
230230
p_subset_from_idx = INTEGER(subsetFromIdx);

src/fastMatch.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ SEXP fastMatch(SEXP x, SEXP y, SEXP xidx, SEXP yidx, SEXP xolength, SEXP tol) {
2929

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

src/massifquant/nmath.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,11 @@ double gamma_cody(double);
4646
#ifndef MATHLIB_STANDALONE
4747

4848
#include <R_ext/Error.h>
49-
# define MATHLIB_ERROR(fmt,x) error(fmt,x);
50-
# define MATHLIB_WARNING(fmt,x) warning(fmt,x)
51-
# define MATHLIB_WARNING2(fmt,x,x2) warning(fmt,x,x2)
52-
# define MATHLIB_WARNING3(fmt,x,x2,x3) warning(fmt,x,x2,x3)
53-
# define MATHLIB_WARNING4(fmt,x,x2,x3,x4) warning(fmt,x,x2,x3,x4)
49+
# define MATHLIB_ERROR(fmt,x) Rf_error(fmt,x);
50+
# define MATHLIB_WARNING(fmt,x) Rf_warning(fmt,x)
51+
# define MATHLIB_WARNING2(fmt,x,x2) Rf_warning(fmt,x,x2)
52+
# define MATHLIB_WARNING3(fmt,x,x2,x3) Rf_warning(fmt,x,x2,x3)
53+
# define MATHLIB_WARNING4(fmt,x,x2,x3,x4) Rf_warning(fmt,x,x2,x3,x4)
5454

5555
#include <R_ext/Arith.h>
5656
#define ML_POSINF R_PosInf
@@ -199,4 +199,4 @@ void attribute_hidden bratio(double a, double b, double x, double y,
199199
double *w, double *w1, int *ierr, int log_p);
200200

201201

202-
#endif /* MATHLIB_PRIVATE_H */
202+
#endif /* MATHLIB_PRIVATE_H */

src/massifquant/xcms_massifquant.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ extern "C" SEXP massifquant(SEXP mz, SEXP intensity, SEXP scanindex,
5959
}
6060

6161
if ((scanrangeFrom < firstScan) || (scanrangeFrom > totalScanNums) || (scanrangeTo < firstScan) || (scanrangeTo > totalScanNums))
62-
error("Error in scanrange \n");
62+
Rf_error("Error in scanrange \n");
6363

6464
//show the progress please
6565
Rprintf("\n Detecting Kalman ROI's ... \n percent finished: ");
@@ -112,17 +112,17 @@ extern "C" SEXP massifquant(SEXP mz, SEXP intensity, SEXP scanindex,
112112
Rprintf(" %d\n", 100);
113113

114114
const char *names[N_NAMES] = {"mz", "mzmin", "mzmax", "scmin", "scmax", "length", "intensity"};
115-
PROTECT(list_names = allocVector(STRSXP, N_NAMES));
115+
PROTECT(list_names = Rf_allocVector(STRSXP, N_NAMES));
116116
for(int j = 0; j < N_NAMES; j++)
117-
SET_STRING_ELT(list_names, j, mkChar(names[j]));
117+
SET_STRING_ELT(list_names, j, Rf_mkChar(names[j]));
118118

119-
PROTECT(peaklist = allocVector(VECSXP, busybody.getPicCounts()));
119+
PROTECT(peaklist = Rf_allocVector(VECSXP, busybody.getPicCounts()));
120120
for (int i=0;i<busybody.getPicCounts();i++) {
121121

122122
std::vector<double> featInfo = busybody.iterOverFeatures(i, pscantime);
123123
//jo int scanLength = int(featInfo.at(5) - featInfo.at(4) + 1);
124124

125-
PROTECT(entrylist = allocVector(VECSXP, N_NAMES));
125+
PROTECT(entrylist = Rf_allocVector(VECSXP, N_NAMES));
126126

127127
//allow for new vars declared to be passed out
128128
PROTECT(vmz = NEW_NUMERIC(1));
@@ -153,7 +153,7 @@ extern "C" SEXP massifquant(SEXP mz, SEXP intensity, SEXP scanindex,
153153
SET_VECTOR_ELT(entrylist, 5, vlength);
154154
SET_VECTOR_ELT(entrylist, 6, vintensity);
155155

156-
setAttrib(entrylist, R_NamesSymbol, list_names); //attaching the vector names
156+
Rf_setAttrib(entrylist, R_NamesSymbol, list_names); //attaching the vector names
157157
SET_VECTOR_ELT(peaklist, i, entrylist);
158158
UNPROTECT(N_NAMES + 1); //entrylist + values
159159
}

src/mzROI.c

+13-13
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct mzROIStruct * checkmzROIBufSize(struct mzROIStruct *mzROI, const unsigned
7676

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

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

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

104104
mzLength->mzvalTotal = newLength;
105105
}
@@ -202,7 +202,7 @@ struct mzROIStruct * insertpeak(const double fMass, const double fInten,
202202

203203
if (ddiff <= ddev)
204204
{ // match (smaller than defined ppm) -> extend this ROI
205-
if ( (i > hpos) || (i<lpos) ) error("! scan: %d \n",scan);
205+
if ( (i > hpos) || (i<lpos) ) Rf_error("! scan: %d \n",scan);
206206
wasfound = TRUE;
207207
//recursive m/z mean update
208208
mzval[i].mz = ((mzval[i].length * mzval[i].mz) + fMass) / (mzval[i].length + 1);
@@ -311,7 +311,7 @@ int i,p,del=0;
311311
}
312312
if (entries > ctScan) {
313313
#ifdef DEBUG
314-
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);
314+
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);
315315
#endif
316316
(*scerr)++;
317317
}
@@ -328,7 +328,7 @@ int i,p,del=0;
328328
p=0;
329329
struct mzROIStruct * tmp = (struct mzROIStruct *) calloc(mzLength->mzval - del, sizeof(struct mzROIStruct));
330330
if (tmp == NULL)
331-
error("findmzROI/cleanup: buffer memory could not be allocated ! (%lu bytes)\n", (mzLength->mzval - del) * sizeof(struct mzROIStruct));
331+
Rf_error("findmzROI/cleanup: buffer memory could not be allocated ! (%lu bytes)\n", (mzLength->mzval - del) * sizeof(struct mzROIStruct));
332332
for (i=0; i < mzLength->mzval; i++) {
333333
if (mzval[i].deleteMe == FALSE) {
334334
tmp[p].mz = mzval[i].mz;
@@ -379,7 +379,7 @@ struct scanBuf * getScan(int scan, double *pmz, double *pintensity, int *pscanin
379379
scanbuf->thisScan= (struct scanStruct *) calloc(N, sizeof(struct scanStruct));
380380
// scanbuf->thisScan= (struct scanStruct *) malloc(N * sizeof(struct scanStruct));
381381
if (scanbuf->thisScan == NULL)
382-
error("findmzROI/getThisScan: Memory could not be allocated!\n");
382+
Rf_error("findmzROI/getThisScan: Memory could not be allocated!\n");
383383

384384
scanbuf->thisScanLength=N;
385385

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

417417
for (idx=idx1;idx <= idx2; idx++)
@@ -463,7 +463,7 @@ SEXP getEIC(SEXP mz, SEXP intensity, SEXP scanindex, SEXP mzrange, SEXP scanrang
463463
scanrangeFrom = INTEGER(scanrange)[0];
464464
scanrangeTo = INTEGER(scanrange)[1];
465465
if ((scanrangeFrom < firstScan) || (scanrangeFrom > ilastScan) || (scanrangeTo < firstScan) || (scanrangeTo > ilastScan))
466-
error("Error in scanrange \n");
466+
Rf_error("Error in scanrange \n");
467467
char *names[2] = {"scan", "intensity"};
468468
PROTECT(list_names = allocVector(STRSXP, 2));
469469
for(i = 0; i < 2; i++)
@@ -508,7 +508,7 @@ SEXP getMZ(SEXP mz, SEXP intensity, SEXP scanindex, SEXP mzrange, SEXP scanrange
508508
scanrangeFrom = INTEGER(scanrange)[0];
509509
scanrangeTo = INTEGER(scanrange)[1];
510510
if ((scanrangeFrom < firstScan) || (scanrangeFrom > ilastScan) || (scanrangeTo < firstScan) || (scanrangeTo > ilastScan))
511-
error("Error in scanrange \n");
511+
Rf_error("Error in scanrange \n");
512512

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

568568
buflength = scanrangeTo - scanrangeFrom +1;
569569
PROTECT(res = NEW_NUMERIC(buflength));
@@ -626,11 +626,11 @@ SEXP findmzROI(SEXP mz, SEXP intensity, SEXP scanindex, SEXP mzrange,
626626

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

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

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

680680
if (fMass < lastMass)
681-
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);
681+
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);
682682
lastMass = fMass;
683683

684684
if (fInten > inoise)

src/xcms_obiwarp.cpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,16 @@ extern "C" SEXP R_set_from_xcms(SEXP valscantime, SEXP scantime, SEXP mzrange, S
3939
double *pscantime2, *pmz2, *pintensity2;
4040
SEXP corrected;
4141

42-
PROTECT(valscantime = coerceVector(valscantime, INTSXP));
43-
mzrange = coerceVector(mzrange, INTSXP);
42+
PROTECT(valscantime = Rf_coerceVector(valscantime, INTSXP));
43+
mzrange = Rf_coerceVector(mzrange, INTSXP);
4444
pvalscantime = INTEGER(valscantime)[0];
4545
pmzrange = INTEGER(mzrange)[0];
4646
pscantime = REAL(scantime);
4747
pmz = REAL(mz);
4848
pintensity = REAL(intensity);
4949

50-
PROTECT(valscantime2 = coerceVector(valscantime2, INTSXP));
51-
mzrange2 = coerceVector(mzrange2, INTSXP);
50+
PROTECT(valscantime2 = Rf_coerceVector(valscantime2, INTSXP));
51+
mzrange2 = Rf_coerceVector(mzrange2, INTSXP);
5252
pvalscantime2 = INTEGER(valscantime2)[0];
5353
pmzrange2 = INTEGER(mzrange2)[0];
5454
pscantime2 = REAL(scantime2);
@@ -120,13 +120,13 @@ extern "C" SEXP R_set_from_xcms(SEXP valscantime, SEXP scantime, SEXP mzrange, S
120120
lmat2.tm_axis_vals(nOut, nOutF);
121121
lmat2.warp_tm(nOutF, mOutF);
122122

123-
PROTECT(corrected = allocVector(REALSXP, length(scantime2)));
124-
for(int i=0; i < length(scantime2);i++){
123+
PROTECT(corrected = Rf_allocVector(REALSXP, Rf_length(scantime2)));
124+
for(int i=0; i < Rf_length(scantime2);i++){
125125
REAL(corrected)[i] = lmat2.tm()->back()[i];
126126
}
127127

128128
UNPROTECT(3);
129129

130130
return corrected;
131131

132-
}
132+
}

0 commit comments

Comments
 (0)