passing arguments to makeContrast
1
0
Entering edit mode
@raffaele-calogero-294
Last seen 9.1 years ago
Italy/Turin/University of Torino
Hi, 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? Thanks Raffaele ---------------------------------------- Prof. Raffaele A. Calogero Bioinformatics and Genomics Unit Dipartimento di Scienze Cliniche e Biologiche c/o Az. Ospedaliera S. Luigi Regione Gonzole 10, Orbassano 10043 Torino tel. ++39 0116705420 Lab. ++39 0116705408 Fax ++39 0119038639 Mobile ++39 3333827080 email: raffaele.calogero at unito.it www: www.bioinformatica.unito.it
• 2.3k views
ADD COMMENT
0
Entering edit mode
@gerhard-thallinger-1552
Last seen 9 weeks ago
Austria
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
ADD COMMENT

Login before adding your answer.

Traffic: 599 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6