-
Notifications
You must be signed in to change notification settings - Fork 50
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
Add $,pSet method to easily access columns in the phenoData #203
Conversation
- Add $, $<- and pData<- methods to easily get and replace/add columns to the phenodata. - Add related unit tests and add documentation.
Codecov Report
@@ Coverage Diff @@
## master #203 +/- ##
==========================================
+ Coverage 71.72% 71.74% +0.01%
==========================================
Files 67 67
Lines 7165 7170 +5
==========================================
+ Hits 5139 5144 +5
Misses 2026 2026
Continue to review full report at Codecov.
|
Thanks @jotsetung, I think this will prove very useful. I'll wait for the new release to merge. On a similar note, I also thought it would be useful to be able to change the behaviour of |
Don't you think that might become a little confusing if |
Hmm, |
I checked the |
I am not sure that it is possible to use library("MSnbase")
data(msnset)
setGeneric("%fd%", function(object, name)standardGeneric("%fd%"))
setGeneric("%pd%", function(object, name)standardGeneric("%pd%"))
setMethod("%fd%", "MSnSet", function(object, name)fData(object)[, as.character(substitute(name))])
setMethod("%pd%", "MSnSet", function(object, name)pData(object)[, as.character(substitute(name))])
msnset %fd% ProteinAccession
# [1] BSA ECA1422 ECA4030 ECA3882 ECA1364 ECA0871
# [7] ECA4512 ECA4513 ECA3969 ECA3082 ECA1032 ECA1294
# [13] ECA4514 ECA1104 ECA3356 ECA4037 ECA0621 ECA1093
# [19] ECA0452 ENO ECA2391 ECA0435 ECA1362 ECA1363
# [25] ECA3566 ECA0435 ECA0691 ECA3566 ECA3377 ECA0978
# [31] ECA2831 ECA4514 ECA0469 ECA4514 ECA4514 ECA0172
# [37] ECA0631 ECA3349 ECA0469 ECA4514 ENO ENO
# [43] ECA4026 ECA3929 ECA4514 ECA4026 ECA4013 BSA
# [49] BSA ECA2186 ENO ECA3349 ECA2421 ECA1443
# [55] ECA3175
# 40 Levels: BSA ECA0172 ECA0435 ECA0452 ... ENO
msnset %pd% mz
# [1] 114.1 115.1 116.1 117.1 ( |
`$$` <- function(x, y) { x[[y]] }
l <- list(a=1, b=2)
l$$b
# Error: unexpected '$' in "l$$"
$$(l, "a")
# Error: unexpected '$' in "$" |
Yes, that was what I realized too, defining Regarding the Eventually we just add the |
Have a look in |
That's exactly our implementation for the |
Following up from @sgibb's example: [1] 1
> `$$` <- function(x, y) { x[[y]] }
> l <- list(a=1, b=2)
> `$`(l, "a")
[1] 1
> `$$`(l, "a")
[1] 1 I think the problem we have is that R can't parse |
An alternative would be to use > .Foo <- setClass("Foo", slots = c(a = "numeric"))
> foo <- .Foo(a = 1:10)
> names(foo@a) <- letters[1:10]
> `$`
.Primitive("$")
> getGeneric("$")
standardGeneric for "$" defined from package "base"
function (x, name)
standardGeneric("$", .Primitive("$"))
<bytecode: 0x1355f40>
<environment: 0x1221b00>
Methods may be defined for arguments: x
Use showMethods("$") for currently available ones.
> setMethod("$", "Foo", function(x, name) x@a[name])
[1] "$"
> foo$a
a
1 but > getGeneric("@")
NULL
> `@`
.Primitive("@")
> setMethod("@", "Foo", function(x, name) x@a[name])
Error in setGeneric(f, where = where) :
‘@’ dispatches internally; methods can be defined, but the generic function is implicit, and cannot be changed.
> setMethod("@", "Foo", function(object, name) object@a[name])
Error in setGeneric(f, where = where) :
‘@’ dispatches internally; methods can be defined, but the generic function is implicit, and cannot be changed. |
I think |
Yes, but sometime the perfect is the enemy of good. I am unsure that |
I am going to merge this. Issue #209 follows up the discussion to directly access |
phenodata.
Basically, It facilitates accessing pheno data columns by just calling
pset$pheno_col
. I find that pretty convenient e.g. inExpressionSet
objects and alike, so I thought it might be nice to have it inMSnbase
as well.Also I added replace methods for the
pData
.