[BioC] passing arguments to makeContrast

Gerhard Thallinger Gerhard.Thallinger at tugraz.at
Fri Feb 10 09:19:45 CET 2006


Dear Raffaele,

> I am trying to build a function in which I will pass the 
> contrasts of a linear model as a parameter of the function.
> The question is how can I pass the contrasts if they are 
> inserted in a object:
> if I do:
> tmp=makeContrasts("ctrl-trt", levels=c("ctrl", "trt"))
> works!
> 
> if instead I do
> mycontrast="ctrl-trt"
> tmp=makeContrasts(mycontrast, levels=c("ctrl", "trt"))
>  it does not and I get the error:
> Error in eval(expr, envir, enclos) : object "mycontrast" not found
> 
> There is any trick to pass my contrasts if they are inserted 
> in an object?

  Yes, there is:

   lev <- c("ctrl", "trt")
   cmd <- paste("tmp <- makeContrasts(", mycontrast, ", levels = lev)", sep =
'"')
   eval(parse(text = cmd))
 
I personally think that makeContrasts() should accept the contrasts as a 
string argument only, this would make live much easier (but would probably
break a lot of existing scripts). 

You ran in similar problems if the contrast starts with a digit:
   cont <- makeContrasts("2h-0h", levels = design)
   Error in parse(file, n, text, prompt) : syntax error in "2h"

hth

Gerhard



More information about the Bioconductor mailing list