[BioC] variable as argument to makeContrasts (limma)
Saroj K Mohapatra
saroj at vt.edu
Tue Jun 2 18:48:13 CEST 2009
Hi Georg:
It is doable, the idea is to create the command string first and then
evaluate it as an R expression.
Frirst, collapse the contrasts. If it is a vector like in your case:
a<-c("B-A","C-B","C-A")
> astr=paste(a, collapse=",")
> astr
[1] "B-A,C-B,C-A"
Then add correct strings before and after.
> prestr="makeContrasts("
> poststr=",levels=design)"
> commandstr=paste(prestr,astr,poststr,sep="")
> commandstr
[1] "makeContrasts(B-A,C-B,C-A,levels=design)"
Now evaluate the command string:
> eval(parse(text=commandstr))
Contrasts
Levels B - A C - B C - A
A -1 0 -1
B 1 -1 0
C 0 1 1
However, 'eval' is a tricky thing (see some comments here on the list
some days back). There might be better (i.e., more straight-forward)
ways of doing this. Hopefully, others would comment.
Best wishes,
Saroj
Georg Otto wrote:
> Hi,
>
> maybe this is a more general R programming question, but I first try it
> here, because the problem occured to me with limma:
>
> I use the function makeContrasts
>
> makeContrasts(...,levels=design)
>
> like this
>
> makeContrasts(B-A,C-B,C-A,levels=design)
>
>
> now instead of giving explicitely "B-A,C-B,C-A" I would like to replace
> this by a variable, eg:
>
> a<-c("B-A","C-B","C-A")
>
> makeContrasts(a,levels=design)
>
> unfortunately, this does not work.
>
> So my question is: how can I make this work, and - more generally - how
> can I replace the "..." option in a function by a variable?
>
> Thanks,
>
> Georg
>
> _______________________________________________
> Bioconductor mailing list
> Bioconductor at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives: http://news.gmane.org/gmane.science.biology.informatics.conductor
>
>
More information about the Bioconductor
mailing list