Skip to content

Commit

Permalink
Add sort option (issue #180)
Browse files Browse the repository at this point in the history
o Add option sortMethod that defaults to "auto" on R < 3.3 and "radix"
  otherwise.
  • Loading branch information
jorainer committed Jan 3, 2017
1 parent 0f18ae6 commit 67278d0
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
7 changes: 5 additions & 2 deletions R/functions-OnDiskMSnExp.R
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,8 @@ precursorValue_OnDiskMSnExp <- function(object, column) {
res <- vector("list", nrow(ms1fd))
for (i in 1:nrow(ms1fd)) {
currentMat <- allSpect[[i]]
o <- order(currentMat[, 1], method = "radix")
## issue #180: use radix sorting for R >= 3.3
o <- order(currentMat[, 1], method = MSnbaseOptions()$sortMethod)
currentMat <- currentMat[o, ]
res[[i]] <- Spectrum1(peaksCount = nrow(currentMat),
scanIndex = ms1fd[i, "spIdx"],
Expand Down Expand Up @@ -424,7 +425,9 @@ precursorValue_OnDiskMSnExp <- function(object, column) {
res2 <- vector("list", nrow(msnfd))
for (i in 1:nrow(msnfd)) {
currentMat <- allSpect[[i]]
o <- order(currentMat[, 1], method = "radix")
## issue #180: use radix sorting for R >= 3.3
## o <- order(currentMat[, 1], method = "radix")
o <- order(currentMat[, 1], method = MSnbaseOptions()$sortMethod)
currentMat <- currentMat[o, ]
res2[[i]] <- Spectrum2(peaksCount = nrow(currentMat),
scanIndex = msnfd[i, "spIdx"],
Expand Down
4 changes: 3 additions & 1 deletion R/methods-Spectrum.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ setMethod("initialize",
if (xor(!missing(mz), !missing(intensity)))
stop("'mz' and 'intensity' or none required.")
if (!missing(mz) & !missing(intensity)) {
o <- base::order(mz, method = "radix")
## issue #180: use radix sorting for R >= 3.3
## o <- base::order(mz, method = "radix")
o <- base::order(mz, method = MSnbaseOptions()$sortMethod)
.Object <- callNextMethod(.Object,
...,
mz = mz[o],
Expand Down
2 changes: 1 addition & 1 deletion R/options.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
##' There are also setters to set options individually. When run
##' without argument, the verbosity setter inverts the current value
##' of the option.
##'
##'
##' @title MSnbase options
##' @param opt The value of the new option
##' @return A \code{list} of MSnbase options and the single option
Expand Down
5 changes: 5 additions & 0 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@

.onLoad <- function(libname, pkgname) {
## Add MSnbase options.
## Use radix sorting for R >= 3.3
sortMeth <- "auto"
if (as.numeric(R.Version()$major) >= 3 & as.numeric(R.Version()$minor) >= 3)
sortMeth <- "radix"
msOps <- list(PARALLEL_THRESH = 1000,
sortMethod = sortMeth,
verbose = FALSE)
options(MSnbase = msOps)
}

0 comments on commit 67278d0

Please sign in to comment.