[R] Invalid connection error message when trying to write a file

Uwe Ligges ligges at statistik.tu-dortmund.de
Mon Dec 16 16:41:31 CET 2013


I guess your problem is that you cannot write toplevel into "c:\" with 
your permissions?

Best,
Uwe Ligges


On 16.12.2013 16:40, John Karon wrote:
> Thanks for pointing out my error after specifying the destination in the
> file(  ) function.  What you proposed also did not work.
> It turns out the solution is to give the file name but not include the
> path; the resulting file is written in the working directory.
> The mystery is that including the path had previously work.
> John Karon
>
> -----Original Message----- From: Uwe Ligges
> Sent: Sunday, December 15, 2013 12:30 PM
> To: John Karon ; r-help at r-project.org
> Subject: Re: [R] Invalid connection error message when trying to write a
> file
>
>
>
> On 15.12.2013 20:13, John Karon wrote:
>> The response below asks what I actually did.
>>
>> I defined a function (details omitted; it computes the data frame
>> LRtest.out); arguments include "path\\filename.csv" to which I want to
>> write a data frame using write.csv(  ).  Repeated executions of the
>> function (without the file(  ) and close(  ) instructions) were
>> successful until 2 days ago, when I received the error message below.  I
>> simplified the code to write a file and received the error message below
>> (same message as before) in response to the commands
>>
>> zz<-file(description="c:\\LRtest.txt","w")
>> write.table(LRtest.out, file="c:\\LRtest.txt", sep="\t")
>> close(zz)
>
> Wrong, *either* use
>
> write.table(LRtest.out, file="c:\\LRtest.txt", sep="\t")
>
> or
>
> zz <- file(description="c:\\LRtest.txt","w")
> write.table(LRtest.out, file=zz, sep="\t")
> close(zz)
>
> Best,
> Uwe Ligges
>
>
>
>
>
>
>
>>
>> Error in file(description = "c:\\LRtest.txt", "w") :
>>   cannot open the connection
>> In addition: Warning message:
>> In file(description = "c:\\LRtest.txt", "w") :
>>   cannot open file 'c:\LRtest.txt': Permission denied
>>
>> This happens whether there is no previous file with that name or an
>> essentially empty file with that name.  In previous executions of code
>> with a path to a folder, executing the file(  )  command would create an
>> empty file.  Now no empty file is created.  The problem persists after
>> rebooting the computer.
>>
>> I also tried writing to the clipboard (description ="clipboard" in the
>> file(  ) command); that was unsuccessful, with file="clipboard" or no
>> file statement in the write.table(  ) command (Word showed there was
>> something to paste, but pasting into an empty Word document did not put
>> text into the document; with no file statement, the data frame was
>> written to the console).
>>
>> I question whether there is a setting that forbids writing to a file.
>> Information on putting the data frame on the clipboard would also help.
>> Thanks for any help.  John Karon
>>
>> -----Original Message----- From: Uwe Ligges
>> Sent: Saturday, December 14, 2013 10:05 AM
>> To: J Karon ; r-help at r-project.org
>> Subject: Re: [R] Invalid connection error message when trying to write a
>> file
>>
>>
>>
>> On 13.12.2013 20:11, J Karon wrote:
>>> I get an invalid connection method error message when trying to write
>>> an R
>>> object from a user-defined function to my hard drive (running Windows 7)
>>> using write.csv.  I have previously not had this problem with the same
>>> user-defined function.  The error message is
>>>
>>> Error in isOpen(file, "w") : invalid connection
>>> In addition: Warning message:
>>> In if (file == "") file <- stdout() else if (is.character(file)) { :
>>>    the condition has length > 1 and only the first element will be used
>>>
>>> Using
>>> zz<-file(description="path","w")
>>> write.csv(  )
>>> close(zz)
>>>
>>> creates an empty file but yields the same error message when I execute
>>> write.csv.
>>
>>
>> Please tell us what you actually did.
>>
>> This works for me:
>>
>> zz <- file(description="path", "w")
>> write.csv(iris, zz)
>> close(zz)
>>
>> Best,
>> Uwe Ligges
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list