Error in gzfile(file, "wb"): cannot open the connection or compressed file
Solution 1:
This is a bit late but for anyone coming here for help, I got this error when I was trying to write a file from RStudio and my destination file path was very long. I realized this could be a problem because when I wrote the file to another location with a shorter name and tried to copy it into my original destination, Windows gave me an error saying "File path too long". You might need to save the original file into another location with a shorter absolute path.
Solution 2:
Maybe you should look here. At the end it says
Note: The most common reason for failure is lack of write permission in the current directory. For save.image and for saving at the end of a session this will shown by messages like
Error in gzfile(file, "wb") : unable to open connection
In addition: Warning message:
In gzfile(file, "wb") :
cannot open compressed file '.RDataTmp',
probable reason 'Permission denied'
So rapidly, if you try getwd()
, look at where is your working directory set. If you're trying to save your document in a place where it's not in your current working directory, it will throw you this error.
At the end of your error message, it says probable reason 'No such file or directory'
Graphics error: Error in gzfile(file, "wb") : cannot open the connection
My diagnosis would be simply that it's trying to save your item in the wrong place and RStudio is not able to find the right place.
Solution 3:
This burned me so hopefully saves someone else some toil. The issue was that the classifiers loaded just fine on OS X but on the Linux deployment system they would fail with the error listed in the question. The issue was the the files on the disk had extension abc.RData
but the code modelAbc <- readRDS(file="abc.Rdata")
. The difference in the upper and lowercase D
in the .RData
vs .Rdata
extension would fail on Linux. It was not very noticeable but check your extensions for case.
Solution 4:
You may have no permission to save file in the directory.
On RStudio, get your working directory by getwd()
.
Then, go to the directory in linux and observe its owner by ls -l
.
Now you can change the owner of the directory by chown -R username directoryname
.
But you must be root.