On 18/10/2010 8:34 PM, Santosh Srinivas wrote:> Dear R-helpers ... any thoughts on the below issue ... will help me
complete
> a small project!
>
>
> Strange problem with download.file . for non existent URL an empty file is
> created but I am not able to delete the without shutting down R
>
> Example:
>
>>
download.file("http://test.com/test.txt","test.txt")
>
> trying URL 'http://test.com/test.txt'
> Error in download.file("http://test.com/test.txt",
"test.txt") :
> cannot open URL 'http://test.com/test.txt'
> In addition: Warning message:
> In download.file("http://test.com/test.txt",
"test.txt") :
> cannot open: HTTP status was '404 Not Found'
>
> If you go to working directory through windows explorer, you can see the
> empty file test.txt but try deleteting the file and it says that the file
is
> locked.
>
> I tried closeAllConnections() but of no use.
>
> Any suggestions?
Suggestion: Don't try to download a nonexistent file to a filename that
you care about. It looks like a bug in download.file is leaving the
file open; Windows won't let you delete open files.
So you could download to tempfile() first to see if it works; if that
fails, you'll be left with a junk file open, but it will be closed when
R quits.
If you want to help, you could look through the internal code to figure
out why the file isn't being closed, and submit a patch.
Duncan Murdoch