r - Examining contents of .rdata file by attaching into a new environment - possible? -


i interested in listing objects in rdata file , loading selected objects, rather whole set (in case may big or may exist in environment). i'm not quite clear on how when there conflicts in names, attach() doesn't work nicely.

1: examining contents of r data file without loading it: question similar, different from, 1 asked @ listing contents of r data file without loading

in case, solution offered was:

attach(filename) ls(pos = 2) detach() 

if there naming conflicts between objects in file , in global environment, warning appears: the following object(s) masked _by_ '.globalenv':

i tried creating new environment, cannot seem attach that. instance, produces same error:

lsfile   <- function(filename){   tmpenv <- new.env()   evalq(attach(filename), envir = tmpenv)   tmpls <- ls(pos = 2)   detach()   return(tmpls) } lsfile(filename) 

maybe i've made mess of things evalq (or eval). there other way avoid naming conflict?

2: if want access object - if there no naming conflicts, can work 1 .rdat file, or copy new one. if there conflicts, how 1 access object in file's namespace?

for instance, if file "sample.rdat", , object surveydata, , surveydata object exists in global environment, how can access 1 file:sample.rdat namespace?

i solve problem loading temporary environment, , copy out what's needed, inefficient.

you can suppress warning setting warn.conflicts=false on call attach. if object masked 1 in global environment, can use get retreive attached data.

x <- 1:10 save(x, file="x.rdata") #attach("x.rdata", pos=2, warn.conflicts=false) attach("x.rdata", pos=2) (x <- 1) # [1] 1 (x <- get("x", pos=2)) # [1]  1  2  3  4  5  6  7  8  9 10 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -