[BioC] variable as argument to makeContrasts (limma)
Martin Morgan
mtmorgan at fhcrc.org
Wed Jun 3 01:29:55 CEST 2009
Hi Georg --
Saroj K Mohapatra wrote:
> 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.
One way is to aim for
do.call(makeConstrasts, myargs)
where the 'myargs' is a list that you can construct any way you like, e.g.,
myargs = list("B-A", "C-B", "C-A", levels=design)
do.call(makeContrasts, myargs)
Martin
>>
>> 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
>>
>>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> 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
--
Martin Morgan
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109
Location: Arnold Building M1 B861
Phone: (206) 667-2793
More information about the Bioconductor
mailing list