[R] assign connections automatically

Tim Howard tghoward at gw.dec.state.ny.us
Tue Feb 1 15:41:03 CET 2005


Thank you for the help!  Both, env=.GlobalEnv and pos=1 do the trick.  
I'm embarrassed I didn't glean this from the assign help pages earlier.

?assign suggests that "env" is there for back compatibility so I'm
going with pos.

Tim Howard

>>>>> James Holtman >>>>>>
try:

> inConnect <- function(){
+ fn <- dir(pattern="*.txt") # grab only *.txt files
+ fn2 <- gsub('.txt', "", fn) # removes the '.txt' from each string
+ for(i in 1:length(fn))
+ assign((fn2[[i]]),file(fn[i], open="r"),env = .GlobalEnv)
+ }
__________________________________________________________
James Holtman        "What is the problem you are trying to solve?"
Executive Technical Consultant  --  Office of Technology, Convergys
james.holtman at convergys.com 
+1 (513) 723-2929

>>> Prof Brian Ripley <ripley at stats.ox.ac.uk> 02/01/05 08:34AM >>>
You are assigning in the frame of the function, not in the user
workspace.
See ?assign and try pos=1 (if that is what you intended) but it might
well 
be better to return a list of objects.




More information about the R-help mailing list