Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/issue778 using Rf_error() #780

Merged
merged 3 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ root = true
charset = utf-8
end_of_line = lf
trim_trailing_whitespace = true
insert_final_newline = false
insert_final_newline = true

[*.R]
indent_style = space
Expand All @@ -18,4 +18,4 @@ indent_style = tab

[.travis.yml]
indent_style = space
indent_size = 2
indent_size = 2
4 changes: 2 additions & 2 deletions .github/workflows/check-bioc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ jobs:
matrix:
config:
- { os: ubuntu-latest, r: 'devel', bioc: 'devel', cont: "bioconductor/bioconductor_docker:devel", rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest" }
- { os: macOS-latest, r: '4.4', bioc: 'devel'}
- { os: windows-latest, r: '4.4', bioc: 'devel'}
- { os: macOS-latest, r: '4.4', bioc: '3.20'}
- { os: windows-latest, r: '4.4', bioc: '3.20'}
env:
R_REMOTES_NO_ERRORS_FROM_WARNINGS: true
RSPM: ${{ matrix.config.rspm }}
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: xcms
Version: 4.5.0
Version: 4.5.1
Title: LC-MS and GC-MS Data Analysis
Description: Framework for processing and visualization of chromatographically
separated and single-spectra mass spectral data. Imports from AIA/ANDI NetCDF,
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# xcms 4.5.1

## Changes in version 4.5.1

- Fix compile errors with R-4.5

# xcms 4.3

## Changes in version 4.3.4
Expand Down
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
12 changes: 6 additions & 6 deletions src/massifquant/nmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ double gamma_cody(double);
#ifndef MATHLIB_STANDALONE

#include <R_ext/Error.h>
# define MATHLIB_ERROR(fmt,x) 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)
# define MATHLIB_WARNING4(fmt,x,x2,x3,x4) warning(fmt,x,x2,x3,x4)
# define MATHLIB_ERROR(fmt,x) Rf_error(fmt,x);
# define MATHLIB_WARNING(fmt,x) Rf_warning(fmt,x)
# define MATHLIB_WARNING2(fmt,x,x2) Rf_warning(fmt,x,x2)
# define MATHLIB_WARNING3(fmt,x,x2,x3) Rf_warning(fmt,x,x2,x3)
# define MATHLIB_WARNING4(fmt,x,x2,x3,x4) Rf_warning(fmt,x,x2,x3,x4)

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


#endif /* MATHLIB_PRIVATE_H */
#endif /* MATHLIB_PRIVATE_H */
12 changes: 6 additions & 6 deletions src/massifquant/xcms_massifquant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ extern "C" SEXP massifquant(SEXP mz, SEXP intensity, SEXP scanindex,
}

if ((scanrangeFrom < firstScan) || (scanrangeFrom > totalScanNums) || (scanrangeTo < firstScan) || (scanrangeTo > totalScanNums))
error("Error in scanrange \n");
Rf_error("Error in scanrange \n");

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

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

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

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

PROTECT(entrylist = allocVector(VECSXP, N_NAMES));
PROTECT(entrylist = Rf_allocVector(VECSXP, N_NAMES));

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

setAttrib(entrylist, R_NamesSymbol, list_names); //attaching the vector names
Rf_setAttrib(entrylist, R_NamesSymbol, list_names); //attaching the vector names
SET_VECTOR_ELT(peaklist, i, entrylist);
UNPROTECT(N_NAMES + 1); //entrylist + values
}
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
14 changes: 7 additions & 7 deletions src/xcms_obiwarp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@ extern "C" SEXP R_set_from_xcms(SEXP valscantime, SEXP scantime, SEXP mzrange, S
double *pscantime2, *pmz2, *pintensity2;
SEXP corrected;

PROTECT(valscantime = coerceVector(valscantime, INTSXP));
mzrange = coerceVector(mzrange, INTSXP);
PROTECT(valscantime = Rf_coerceVector(valscantime, INTSXP));
mzrange = Rf_coerceVector(mzrange, INTSXP);
pvalscantime = INTEGER(valscantime)[0];
pmzrange = INTEGER(mzrange)[0];
pscantime = REAL(scantime);
pmz = REAL(mz);
pintensity = REAL(intensity);

PROTECT(valscantime2 = coerceVector(valscantime2, INTSXP));
mzrange2 = coerceVector(mzrange2, INTSXP);
PROTECT(valscantime2 = Rf_coerceVector(valscantime2, INTSXP));
mzrange2 = Rf_coerceVector(mzrange2, INTSXP);
pvalscantime2 = INTEGER(valscantime2)[0];
pmzrange2 = INTEGER(mzrange2)[0];
pscantime2 = REAL(scantime2);
Expand Down Expand Up @@ -120,13 +120,13 @@ extern "C" SEXP R_set_from_xcms(SEXP valscantime, SEXP scantime, SEXP mzrange, S
lmat2.tm_axis_vals(nOut, nOutF);
lmat2.warp_tm(nOutF, mOutF);

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

UNPROTECT(3);

return corrected;

}
}
Loading