2

I have this formula for Rpackage DESEeq which takes ~Strain as formula. I have type.formula <- "Strain" and want to replace the Strain in formula with type.formula and be able to run the code below. How can I do this? So instead of this code below:

dds <- DESeqDataSetFromMatrix(countData = count.mat , colData = cond, design = ~Strain)

I want to run it like this:

dds <- DESeqDataSetFromMatrix(countData = count.mat , colData = cond, design = ~eval(type.formula))
MAPK
  • 5,635
  • 4
  • 37
  • 88
  • 6
    Use `as.formula(paste("~", type.formula))`. – Rui Barradas Oct 17 '17 at 07:54
  • @RuiBarradas Thanks! – MAPK Oct 17 '17 at 07:57
  • @RuiBarradas Please post that as an answer, so taht MAPK can accept the answer and everyone can see, that the question has been answered. – Bernhard Oct 17 '17 at 08:03
  • @Bernhard If I post this as answer it will be flagged for its length. It's so simple I really don't feel like posting it as an answer. – Rui Barradas Oct 17 '17 at 08:12
  • Something like `type.formula <- as.name(type.formula); eval(bquote(DESeqDataSetFromMatrix(countData = count.mat , colData = cond, design = ~.(type.formula)))` is usually preferable because it shows the correct formula in the model output. Please provide a reproducible example. – Roland Oct 17 '17 at 08:44

0 Answers0