[R] a string to enviroment or function

Duncan Murdoch murdoch at stats.uwo.ca
Mon Jun 25 23:31:18 CEST 2007

On 25/06/2007 4:19 PM, Weiwei Shi wrote:
> 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.

One of the examples in ?library shows how to do what you want.

pkg <- "splines"
library(pkg, character.only = TRUE)

Duncan Murdoch

>>> Weiwei Shi, Ph.D
>>> Research Scientist
>>> GeneGO, Inc.

P.S. If you think this was helpful, one of the ways to contribute back 
to the R project would be to ask your employer to become an 
institutional member:  see


More information about the R-help mailing list