Re: [R] search path question

2007-05-30 Thread Barry Rowlingson
Prof Brian Ripley wrote: You could do this via a search_file() connection wrapper, but there is a problem with ensuring connections get closed (which on.exit does here). I'm not sure exactly what you mean by a 'search_file() connection wrapper', but I have realised that its probably a

Re: [R] search path question

2007-05-30 Thread Prof Brian Ripley
I meant essentially the same thing but returning file(fixed_up_name). You can vectorize this BTW: search_file - function(name, path=getOption(scanpath)) { fp - c(name, file.path(path, name)) # better to use direct name first fp - fp[file.exists(fp)] if(length(fp)) file(fp[1]) else

[R] search path question

2007-05-29 Thread Zhiliang Ma
Hi R users, Is there a simple function that can add a folder into current R search path? For example, suppose my current work directory is D:\work, but my input files are stored in folder C:\inFiles\, I know I can change work directory or add C:\inFiles\ before files name when I scan them, but I

Re: [R] search path question

2007-05-29 Thread Vladimir Eremeev
Yes, it is. The original is here http://finzi.psych.upenn.edu/R/Rhelp02a/archive/92829.html However, it requires some modifications. Here they are. Sorry, I can test it only in Windows. search.source - function(file, path=Sys.getenv(PATH), ...) { for(p in

[R] search path question

2007-05-29 Thread Zhiliang Ma
Hi R users, Is there a simple function that can add a folder into current R search path? For example, suppose my current work directory is D:\work, but my input files are stored in folder C:\inFiles\, I know I can change work directory or add C:\inFiles\ before files name when I scan them, but I

Re: [R] search path question

2007-05-29 Thread Barry Rowlingson
Zhiliang Ma wrote: I want to find a function that can simply add C:\inFiles\ into R's search path, so that we I scan a file R will go to all the search paths to find it. In matlab, path(path,C:\inFiles) will do this job, I'm just wondering if there is a similar function in R can do this job.

Re: [R] search path question

2007-05-29 Thread David Forrest
On Tue, 29 May 2007, Zhiliang Ma wrote: Hi R users, Is there a simple function that can add a folder into current R search path? This works for adding libraries to your search path, but I don't think it would work for finding data files outside of your getwd() quite as you'd like:

Re: [R] search path question

2007-05-29 Thread Zhiliang Ma
Thanks, Barry. In fact, I have a function just like yours, and I'm looking for a simple alternative function, which is like path in Matlab. On 5/29/07, Barry Rowlingson [EMAIL PROTECTED] wrote: Zhiliang Ma wrote: I want to find a function that can simply add C:\inFiles\ into R's search

Re: [R] search path question

2007-05-29 Thread Barry Rowlingson
Zhiliang Ma wrote: Thanks, Barry. In fact, I have a function just like yours, and I'm looking for a simple alternative function, which is like path in Matlab. Dont think it can be done - if you look at the code for 'scan', it disappears off into internal() calls to do the business of

Re: [R] search path question

2007-05-29 Thread Prof Brian Ripley
Actually, it does if (is.character(file)) if (file == ) file - stdin() else { file - file(file, r) on.exit(close(file)) } so all the searching is done in the file() connection. You could do this via a search_file()