Error in gzfile(file, "rb") - what should I do? - r

I'm going to write shortly, because my english is not perfect.
My code is:
explanatory=readRDS("explanatory_complete.Rds")
And I want knit pdf or word document, I receive this message:
Error in gzfile(file, "rb")- can't oppen connection
Where is problem? I set the right working directory.

Try with explanatory<-readRDS('filename.rds') this works for me.

Not sure if this is your case but I ran into
Error in gzfile(file, "rb")- can't open connection
when I tried to read a large file after it was downloaded using rsync. This was due to different file access permissions set by rsync than my Windows 10 system. The error was fixed in a local MobaXterm session using
chmod u+rwx filename
(change filename to your files)

The file likely doesn't exist in your working directory. This often happens to me when I have changed my working directory and forgotten to change it back.

Have you tried saving the new R/RMD file first?
I faced the same issue and problem was that, I was not saving the new file first therefore the R session was unable to understand the path for RDS file.
After I saved the file (in the same folder, but not a necessity) and ran the readRDS, it worked.

I had this issue. For me, it was being caused by an update.packages() call in a script my RMD document was sourcing. I'm sure there is a more elegant solution, but I just put a # in front of this line of code for knitting this RMD and then removed it again after

Check your exact file name and the working directly. it might be .rds missing in your saved file name.

Related

Why do I keep getting an error when trying to import my file?

I'm trying to read csv file using R notebook and keep getting this error:
Error: 'Examples/data/starbucks.csv' does not exist in current
working directory ('C:/Users/c227466/Desktop')
I'm not sure what's going on!
This is the code I used:
starbucks <- read_csv("Examples/data/starbucks.csv")
starbucks
Your working directory is your desktop (which is not recommended). On your desktop, you should add a folder "Examples" and, in it, another folder "data" and your file there.

R studio will not remember my file path for a code chunk

When I run the following code I get an error.
library(tidyverse)
day <- read.csv("day.csv")[, -1]
glimpse(day)
Result:
Show in New Window
Error in file(file, "rt") : cannot open the connection
However when I specify the file path it works:
library(tidyverse)
setwd("~/UofUProjects/IS6489")
day <- read.csv("day.csv")[, -1]
glimpse(day)
I don't want to have to specify the file path for every single code chunk I run. Is this a setting I may have accidentally disabled? I tried deleting an re adding the file. I also tried clicking more and choosing set working directory and I still get the same error. I also tried updating Rstudio and R to the newest versions.
here is my working directory
The R markdown file I was using was saved in my download folder instead of my project folder. I was trying to specify the working directory folder with the R studio settings, and thought it would recognize however it did not work unless I actually saved the R markdown file in the project folder or used setwd(). I ran the code without the setwd() after I saved in the correct location and it worked just the way I wanted it to.

Unable to change directory in R Studio - problem with oneDrive

I am facing a problem while trying to change directory to read a csv in Rstudio.
When I type getwd() I get this as my directory:
C:/Users/giorg/OneDrive/Υπολογιστής/MSc_Data_Science_&_CI/Introduction to Statistical methods for Data Science/Coursework
So when I try to read my csv I get that error:
C:/Users/giorg/OneDrive/ÕðïëïãéóôÞò/MSc_Data_Science_&_CI/Introduction to Statistical methods for Data Science/Coursework/x.csv': No such file or directory
I tried to change through Global options > General but I still have oneDrive in my path
And when I try with setwd() I get :
setwd("C:/Users/giorg/OneDrive/Υπολογιστής/Giorgos")
Error in setwd("C:/Users/giorg/OneDrive/<U+03A5>p<U+03BF><U+03BB><U+03BF><U+03B3><U+03B9>st<U+03AE><U+03C2>/Giorgos")
cannot change working directory
Any suggestions about what should I do?
I had the same problem at some point. When I tried to change the directory I got the same error. In my case, the problem started when I changed the language of my computer. The file which I wanted to use as directory named in Greek language and after I turned my computer to English, R couldn't recognize it.
The problem solved when I renamed the file with English characters.

My vim keeps showing errors regarding diff and gzip

I was trying to diff two files with gvimdiff a.txt and b.txt and vim shows
E97:Cannot Create diffs
and when i tried opening a .gz file it shows
Error detected while processing function gzip#read: line 44: Error:
Could not read uncompressed file
Just to make sure i did not mess up my .vimrc,.cshrc and .alias file i reverted back to empty .vimrc and .vim folder in my home directory, similarly i removed all my additions in .cshrc and .alias.
This issue is bugging me since a day and it was fine few hours before.
Is there a way that i can get this resolved without installing any files with sudo?
Please suggest some changes to get back to original.
vim used is vim7.4
Edit:
The issue keeps coming back again.
to check some vim help, I tried :help E97 and it shows the same error
Is the colorcheme file creating a issue here?
I am using solarized as color scheme picked up from github.

Having trouble setting working directory

I created a folder in order for it to be the main work directory meaning all the files I create go there, and files I read will be from there.
For some reason after I created the folder and I'm trying to set it as the working directory I get this message:
Error in setwd("~/") : cannot change working directory
When I try to create files they are saved somewhere different and I get an error when trying to load them. I used the scan function and got:
Error in file(file, "r") : cannot open the connection
In addition: Warning message:
In file(file, "r") : cannot open file 'ff': No such file or directory
The command setwd("~/") should set your working directory to your home directory. You might be experiencing problems because the OS you are using does not recognise "~/" as your home directory: this might be because of the OS, or it might be because of not having set that as your home directory elsewhere.
As you have tagged the post using RStudio:
In the bottom right window move the tab over to 'files'.
Navigate through there to whichever folder you were planning to use as your working directory.
Under 'more' click 'set as working directory'
You will now have set the folder as your working directory. Use the command getwd() to get the working directory as it is now set, and save that as a variable string at the top of your script. Then use setwd with that string as the argument, so that each time you run the script you use the same directory.
For example at the top of my script I would have:
work_dir <- "C:/Users/john.smith/Documents"
setwd(work_dir)
This may help...
use the following code and browse the folder you want to set as the working folder
setwd(choose.dir())
I just had this error message happen. When searching for why, I figured out that there's a related issue that can occur if you're not paying attention - the same error occurs if the directory you are trying to move into does not exist.
Maybe it is the case that you have your path in couple of lines, you used enter to make it? If so, then part of you paths might look like that "/\nData/" instead of "/Data/", which causes the problem. Just set it to be in one line and issue is solved!

Resources