Hi Peter
Perhaps "get" is what you need? foo.bar <- list( "a"= "a", "b"=1 ) save( file="foo.bar.RData", foo.bar ) rm( foo.bar ) my.fn <- function( fname ) { load( fname ) attach( get(ls( pat="foo" )) ) # works #attach( foo.bar ) # works } Regards JS -----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Peter Waltman Sent: 20 September 2007 20:24 To: Leeds, Mark (IED) Cc: r-help@r-project.org Subject: Re: [R] how can I attach a variable stored in Hi Mark - Thanks for the reply. Sorry I didn't really clarify too well what I'm trying to do. The issue is not that I can't see the variable that gets loaded. The issue is that the variable is a list variable, and I'd like to write a function that will take the .RData filename and attach the variable it contains so that I can more easily access its contents, i.e. foo.bar <- list( "a"= "a", "b"=1 ) save( file="foo.bar.RData", foo.bar ) rm( foo.bar ) my.fn <- function( fname ) { load( fname ) attach( ls( pat="foo" ) ) # I want to attach( foo.bar ), but this doesn't work } ls() # prints out "foo.bar" attach( ls( ) ) # still doesn't work attach( foo.bar ) # works So, basically, the question is how can I attach the variable that's stored in a file if I don't already know it's name? Thanks again! Peter ______________________________________________ R-help@r-project.org 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.