[R] how to know if a file exists on a remote server?

2010-11-30 Thread Baoqiang Cao
Hi, I'd like to download some data files from a remote server, the problem here is that some of the files actually don't exist, which I don't know before try. Just wondering if a function in R could tell me if a file exists on a remote server? I searched this mailing list and after read severals

Re: [R] how to know if a file exists on a remote server?

2010-11-30 Thread Henrique Dallazuanna
Take a look on ?file_test On Tue, Nov 30, 2010 at 2:10 PM, Baoqiang Cao bqcaom...@gmail.com wrote: Hi, I'd like to download some data files from a remote server, the problem here is that some of the files actually don't exist, which I don't know before try. Just wondering if a function in R

Re: [R] how to know if a file exists on a remote server?

2010-11-30 Thread jim holtman
?file.exists On Tue, Nov 30, 2010 at 11:10 AM, Baoqiang Cao bqcaom...@gmail.com wrote: Hi, I'd like to download some data files from a remote server, the problem here is that some of the files actually don't exist, which I don't know before try. Just wondering if a function in R could tell

Re: [R] how to know if a file exists on a remote server?

2010-11-30 Thread Jeff Newmiller
Neither file_test nor file.exists address the OP question, since both of these depend on the filesystem stat call, which doesn't work via arbitrary remote access protocols such as http. Baoqiang Cao: The simplest answer is that if you want the file, try to download it, and deal with any error

Re: [R] how to know if a file exists on a remote server?

2010-11-30 Thread steven mosher
I would use RCurl. if you have, for example, the url of an ftp site you can merely do a getURL() and the contents will be returned. That call will return data that can be coerced into a data.frame that will look like a directory structure listing the file names. If you need code just ask, but

Re: [R] how to know if a file exists on a remote server?

2010-11-30 Thread steven mosher
using RCurl getFtpList - function(ftp){ # the structure returned is dependent on the ftp site as there are # various formats for directory listings dependent upon the server # and the OS. you will need to play with this. # have a look at the ftp with your browser first and

Re: [R] how to know if a file exists on a remote server?

2010-11-30 Thread Baoqiang Cao
Thanks Steven! It is excellent code indeed! On Tue, Nov 30, 2010 at 11:26 AM, steven mosher mosherste...@gmail.com wrote:  I would use RCurl.  if you have, for example, the url of an ftp site you can merely do a getURL() and the contents will be returned. That call will return data that can

Re: [R] how to know if a file exists on a remote server?

2010-11-30 Thread steven mosher
No problem, you can also get the directory with a curlOption of dirlistonly see the example code in the package. This will depend on the version of libcurl that you have. If you have an older version, my code will get you the directory. From the Rcurl examples: the files within a directory.

Re: [R] how to know if a file exists on a remote server?

2010-11-30 Thread Baoqiang Cao
Thanks Steven again! I have to say that these codes are fairly sophisticated to me, but I enjoy using already! BC On Tue, Nov 30, 2010 at 12:02 PM, steven mosher mosherste...@gmail.com wrote: No problem, you can also  get the directory with a curlOption of dirlistonly see the example code in

Re: [R] how to know if a file exists on a remote server?

2010-11-30 Thread Georg Ruß
On 30/11/10 10:10:07, Baoqiang Cao wrote: I'd like to download some data files from a remote server, the problem here is that some of the files actually don't exist, which I don't know before try. Just wondering if a function in R could tell me if a file exists on a remote server? Hi

Re: [R] how to know if a file exists on a remote server?

2010-11-30 Thread steven mosher
here: getFtpList - function(ftp){ # column 1= literal string first position mean file # column 2= number 1 # column 3 =owner # column 4 = group # column 5 =file size # colmn 6 =Month # column 7 =Day # column 8 =Time (year) # column 9 =FileName # txt - getURL(ftp) dir - read.table(

Re: [R] how to know if a file exists on a remote server?

2010-11-30 Thread Baoqiang Cao
Hi Georg, Your code does work, I mean, it doesn't give me any error message, which is critical for me because I need use it in a loop and plus I don't know how to catch error message. Before your message, I was using download.file but the loop was stopped because of the error message when a file

Re: [R] how to know if a file exists on a remote server?

2010-11-30 Thread steven mosher
study trycatch() also, be awre that even with RCurl, that you may find the file there and then fail or lose the connection. worse still you may get a currupt file on download. So there is a lot of checking to do to make bullet proof code that downloads files. On Tue, Nov 30, 2010 at 3:16

Re: [R] how to know if a file exists on a remote server?

2010-11-30 Thread Baoqiang Cao
I must say that your reminder is exactly what happened on me, that is, the file is there but some of the downloaded files are corrupted. The download.file didn't return anything alarming, but just could't open some files. The problem was solved in my case by turning on method=wget. Thanks again!