Reputation: 415
I'm trying load a rds
file which should contain some data.
Professor says to use readRDS()
, however R gives this long error message which I've not been able to decipher myself.
I'm trying to load the file and place it in an Object.
I hope that someone are able to provide some clever solution to this problem.
Canteen_clean <- readRDS("C:/Users/a_s_j/OneDrive/Studie/Cand.merc.Business Intelligence/1. Semester/R for Business Analytics/.Rproj/39 - Graphics/Exercises02/canteen_clean.rds")
Error in gzfile(file, "rb") : cannot open the connection
In addition: Warning message: In gzfile(file, "rb") : cannot open compressed file 'C:/Users/a_s_j/OneDrive/Studie/Cand.merc.Business Intelligence/1. Semester/R for Business Analytics/.Rproj/39 - Graphics/Exercises02/canteen_clean.rds', probable reason 'No such file or directory'
I'm using:
pacman::p_load("pacman", "tidyverse")
to load the packages that should be necessary.
Upvotes: 30
Views: 161191
Reputation: 41
You can try using setwd()
reach to that folder location then use
list.files()
to list all the files present in that folder
then use
t1 <- readRDS("/filename.rds")
head(t1)
to get that data.
Hope it solves your issue.
---------CODE---------------------------
> setwd(""C:/Users/a_s_j/OneDrive/Studie/Cand.merc.Business
> Intelligence/1. Semester/R for Business Analytics/.Rproj/39 -
> Graphics/Exercises02")
>
> list.files()
>
> t1 = readRDS("canteen_clean.rds") head(t1)
Upvotes: 4
Reputation: 44788
Rather than typing a long file path, a really good idea in R is to let the system do the typing for you. That is, do something like this:
filename <- file.choose()
Canteen_clean <- readRDS(filename)
The first line will open the usual file open dialog box; you can select the file you want, and the name will be stored in the filename
variable. The second line will use that name to open it.
Upvotes: 40
Reputation: 23
Try to use \\ instead of /. That is what works for me.
If this is not working there is a chance that the rds file is destroyed so you need either to recreate it or if you have access to get a new copy then try with a new copy. I had the same issue once.
I hope that this helps
Upvotes: 1