Skip to content
Prev 334462 / 398506 Next

Invalid connection error message when trying to write a file

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)

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:
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