. Advertisement .
..3..
. Advertisement .
..4..
I’m building a new program but when I run it, an error pops up. The error displayed is as follows:
Error in file(file, ifelse(append, "a", "w")) : cannot open the
connection In addition: warning message: In file(file, ifelse(append,
"a", "w")) : cannot open file 'C:/mypath/myfile.txt' : No such file
or directory
Error in file(file, ifelse(append, "a", "w")) : cannot open the
connection
In addition: warning message: In file(file, ifelse(append,
"a", "w")) : cannot open file 'C:/mypath/myfile.txt' : Permission denied
I have tried several workarounds, but they still do not get the desired results. If you have come across this situation and have a solution for the “error in file(file, ifelse(append, “a”, “w”)) : cannot open the connection” problem, pls let me know. Here is what I do:
myvector <- c(3.45235, 1.32525, ... , 2.41351) # some numbers
write(myvector, "C:/mypath/myfile.txt") # I use "/" instead of ""
file.exists("C:/")
write(myvector, "C:/myfile.txt")
Thanks!
The cause:
The reason of this problem can be in the name of file. For instance, we have got this issue when in the name of the file there was
"\ "
, because a dynamic list has names.Solution:
This error can be resolve by using:
sometext = gsub("/"," ", sometext)
.This answer was shared with a little more explanation here. But the gist is:
To see if the file is locked by another user, open it in Excel. I received the same error messages, and I was able to determine that the file was locked by a colleague on their computer. This prevented me from editing it.