hi, get.vars.name.prefix<-function(prefix){ result<-list() len<-nchar(prefix) var.names<-ls(name=1,pattern=prefix) #name=1 probably wrong option print(var.names) for(i in 1:length(var.names)){ name<-var.names[i] field<-substr(name,len+1,nchar(name)) result[[field]]<-get(name) } result } for example x.1<-1 x.2<-2 get.vars.name.prefix("x.") should return 1,2 this does not work if i call if from within another function: g<-function(){ x.1<-1 x.2<-2 get.vars.name.prefix("x.") # should return 1,2, nothing else } i would like the environment specified within ls(...) to be that of the body of the function that calls get.vars.name.prefix. apparently name=1 is probably not the right option. thanks. [[alternative HTML version deleted]]