Skip to content

Commit

Permalink
Fix trimws generic/methods
Browse files Browse the repository at this point in the history
 o Fix trimws generic/methods with useAsDefault (see issue #75)
   <2016-02-02 Tue>
 o add exprs,MSnSet-method alias (since exprs is now exported)
   <2016-02-02 Tue>
  • Loading branch information
LaurentGatto committed Feb 2, 2016
1 parent f3125a8 commit 3c07de7
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 6 deletions.
6 changes: 5 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
CHANGES IN VERSION 1.19.11
--------------------------

o Fix trimws generic/methods with useAsDefault (see issue #75)
<2016-02-02 Tue>
o add exprs,MSnSet-method alias (since exprs is now exported)
<2016-02-02 Tue>

CHANGES IN VERSION 1.19.10
--------------------------
o export exprs, fvarLabels, and sampleNames[<-] <2016-01-30 Sat>
Expand Down
8 changes: 7 additions & 1 deletion R/AllGenerics.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,10 @@ setGeneric("fnamesIn", function(x, y, ...) standardGeneric("fnamesIn"))
## setGeneric("chromatogram", function(object, ...) standardGeneric("chromatogram"))

## base::trimws
setGeneric("trimws", function(x, ...) standardGeneric("trimws"))
.trimws.useAsDefault <- function (x, which = c("both", "left", "right"), ...)
base::trimws(x, which, ...)

setGeneric("trimws", signature = "x",
function(x, which = c("both", "left", "right"), ...)
standardGeneric("trimws"),
useAsDefault=.trimws.useAsDefault)
8 changes: 4 additions & 4 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -876,17 +876,17 @@ utils.colSd <- function(x, na.rm = TRUE) {


setMethod("trimws", "data.frame",
function(x, ...) {
function(x, which, ...) {
for (i in 1:ncol(x)) {
if (inherits(x[, i], "character"))
x[, i] <- base::trimws(x[, i], ...)
x[, i] <- base::trimws(x[, i], which)
}
x
})

setMethod("trimws", "MSnSet",
function(x, ...) {
fData(x) <- trimws(fData(x), ...)
function(x, which, ...) {
fData(x) <- trimws(fData(x), which, ...)
x <- logging(x, "Trimmed featureData white spaces")
x
})
1 change: 1 addition & 0 deletions man/MSnSet-class.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
\alias{MSnSet}

%% TODO add methods
\alias{exprs,MSnSet-method}
\alias{dim,MSnSet-method}
\alias{fileNames,MSnSet-method}
%%\alias{normalise,MSnSet-method}
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test_trimws.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ test_that("trimws data.frame vs MSnSet ", {
dfr2 <- trimws(fData(dunkley2006))
expect_identical(fData(d2), dfr2)
})

test_that("check that base:::trimws still works", {
expect_equal(trimws(" xx "), "xx")
expect_equal(trimws(" xx ", "left"), "xx ")
expect_equal(trimws(" xx ", "right"), " xx")
})

0 comments on commit 3c07de7

Please sign in to comment.