Hi Guys,
I have always some trouble when I have to translate my BASH strategy to R. I am using edgeR for differential analysis, and have 16 lrts, named lrt1 to lrt16. Now I want to make MA plot in a for loop, and want to use paste to direct to the lrt1 to lrt16, like this.
i=1
summaryDE<-summary(de <- decideTestsDGE(paste0("lrt",i), p=0.05))
Error in decideTestsDGE(paste0("lrt", i), p = 0.05) :
Need DGEExact or DGELRT object
When I use lrt1 instead of the paste0 stuff it does work :/
What did I forget? Thanks in advance!
Ben
My first guess is that your paste returns a string, not the object. A real simple toy example shows you that:
This cat returns the string "a22" and not the value of the variable a22 ('foo')
In contrast, observe the following:
This cat returns 'foobarbaz' (no separator specified) and accesses the value behind the object.
Thanks Wouter, if I understand correct it is not possible to paste the object names together in a for loop? But I have to first make a list with lrt1 to lrt16, and loop thru it?
That would work I guess. How did you create the lrt objects? Perhaps you can just append each object, after it's created, to a vector and then loop over it. Or if you are working interactively, do some lazy stuff like
paste(paste0("lrt", 1:16), collapse = ', ')
and copy paste that in your new vectorLooks stupid, might be a better way to do this but if it works it's no longer stupid right?
I found out that I have to put
get
before it...Thanks for the help!
So there was a better way to do it! Good job ;-)