Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in gzfile(file, "wb"): cannot open the connection or compressed file

Tags:

r

gzip

statistics

I'm trying to run two things: first, I'm creating a PDF with 4x5, ending with dev.off(), and then trying to create a new graph. However, after starting the second plot, I get:

Error in gzfile(file, "wb") : cannot open the connection
In addition: Warning message:
In gzfile(file, "wb") :
  cannot open compressed file '/var/folders/n9/pw_dz8d13j3gb2xgqb6rfnz00000gn/T/RtmpTfm1Ur/rs-graphics-822a1c83-b3fd-46c3-8028-4e0778f91d0c/4db4b438-ac35-403b-b791-e781baba152c.snapshot', probable reason 'No such file or directory'
Graphics error: Error in gzfile(file, "wb") : cannot open the connection

What is this error? The working directory is one I have read/write access to, and my hard drive isn't full.

Also, I'm using RStudio.

like image 290
Andrew Min Avatar asked Mar 12 '13 13:03

Andrew Min


9 Answers

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.

like image 73
AHegde Avatar answered Nov 20 '22 17:11

AHegde


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.

like image 45
M. Beausoleil Avatar answered Nov 20 '22 19:11

M. Beausoleil


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.

like image 33
Joshcodes Avatar answered Nov 20 '22 18:11

Joshcodes


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.

like image 43
pyy Avatar answered Nov 20 '22 18:11

pyy


Problem resolved by specifying full file path:

saveRDS(df,'C:\\users\\matt\\desktop\\code\\df.Rdata')
like image 2
user2723494 Avatar answered Nov 20 '22 19:11

user2723494


I faced this issue lately. Try turning off your anti-virus and build the package, it might help. It worked for me. Usually anti-virus blocks the permissions and you could avoid it by disabling for sometime just before building a package.

like image 2
Chanukya Patnaik Avatar answered Nov 20 '22 19:11

Chanukya Patnaik


I was trying to save an RDS file to my local Dropbox folder so it syncs with my Dropbox. I figured out I got the same error because I was trying to create a new folder and looks like saveRDS cannot create a new folder, but it can add files to existing folders. So I changed the path to add the file into an existing folder and it worked!

like image 2
Kshitiz Khanal Avatar answered Nov 20 '22 17:11

Kshitiz Khanal


In my case it was Windows Defender which was preventing Rstudio to write any file on hard drive. Either you need to turn Controlled Folder Access off or add Rstudio in the exclusion list.enter image description here

like image 1
M.Qasim Avatar answered Nov 20 '22 18:11

M.Qasim


I also had this problem when working with RStudio and R Markdown. I was getting this error message and had an annoying number of fatal errors which closed RStudio. My issue was that I was working off a network drive and either the name was too long, as in @AHedge above or my network firewalls were giving me trouble. For the moment, I have moved my working files to my desktop and things seem to be working fine. Not sure what this means for my file management over time.

like image 1
Adrienne B Avatar answered Nov 20 '22 18:11

Adrienne B