[R] a string to enviroment or function
Martin Morgan
mtmorgan at fhcrc.org
Mon Jun 25 23:28:57 CEST 2007
Weiwei
See ?library and the character.only argument.
> f <- function(x) library(x)
> f("hgu95av2")
Error in library(x) : there is no package called 'x'
> f <- function(x) library(x, character.only=TRUE)
> f("hgu95av2")
> search()
[1] ".GlobalEnv" "package:hgu95av2" "package:stats"
[4] "package:graphics" "package:grDevices" "package:utils"
[7] "package:datasets" "package:methods" "Autoloads"
[10] "package:base"
Also
> g <- function(x) as.list(get(paste(x, "ENTREZID", sep="")))
> ll <- g("hgu95av2")
> length(ll)
[1] 12625
and finally reverseSplit in Biobase and revmap in AnnotationDbi might
be helpful (though AnnotationDbi is only available with R-devel and
revmap seems not to be documented).
> res <- revmap(hgu95av2ENTREZID)
> hgu95av2ENTREZID[["1190_at"]]
[1] 5800
> res[["5800"]]
[1] "1190_at" "32199_at"
Martin
"Weiwei Shi" <helprhelp at gmail.com> writes:
> then how to do this
>
> f1 <- function(mylab){
> library(mylab)
> ...
> }
>
> it seems that if you call
> library("hgu133a") # which is file
> # but
> library(mylab) # even you pass "hgu133a" as parameter, it still
> complains about "mylab" does not exist. It seems that it consider
> mylab as package instead of its value.
>
>
> On 6/25/07, jim holtman <jholtman at gmail.com> wrote:
>> I think that you might want:
>>
>> t0 <- (paste("hgu133a", "ENTREZID", sep=""))
>> xx <- as.list(get(t0)) # make it work like xx<-as.list(hgu133aENTREZID)
>>
>>
>>
>>
>> On 6/25/07, Weiwei Shi <helprhelp at gmail.com> wrote:
>> >
>> > Hi,
>> >
>> > I am wondering how to make a function Fun to make the following work:
>> >
>> > t0 <- (paste("hgu133a", "ENTREZID", sep=""))
>> > xx <- as.list(Fun(t0)) # make it work like xx<-as.list(hgu133aENTREZID)
>> >
>> > thanks,
>> > --
>> > Weiwei Shi, Ph.D
>> > Research Scientist
>> > GeneGO, Inc.
>> >
>> > "Did you always know?"
>> > "No, I did not. But I believed..."
>> > ---Matrix III
>> >
>> > ______________________________________________
>> > R-help at stat.math.ethz.ch mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>> >
>>
>>
>>
>> --
>> Jim Holtman
>> Cincinnati, OH
>> +1 513 646 9390
>>
>> What is the problem you are trying to solve?
>
>
> --
> Weiwei Shi, Ph.D
> Research Scientist
> GeneGO, Inc.
>
> "Did you always know?"
> "No, I did not. But I believed..."
> ---Matrix III
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Martin Morgan
Bioconductor / Computational Biology
http://bioconductor.org
More information about the R-help
mailing list