Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I load an rds file into R

Tags:

r

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.

like image 968
Anders Jørgensen Avatar asked Nov 29 '19 15:11

Anders Jørgensen


People also ask

How do I load a file into R?

To successfully load this file into R, you can use the read. table() function in which you specify the separator character, or you can use the read. csv() or read. csv2() functions.

What is an RDS file in R?

R also has two native data formats—Rdata (sometimes shortened to Rda) and Rds. These formats are used when R objects are saved for later use. Rdata is used to save multiple R objects, while Rds is used to save a single R object. See below for instructions on how to read and load data into R from both file extensions.

How do I open an RData file in R?

The easiest way to load the data into R is to double-click on the particular file yourfile. RData after you download it to your computer. This will open in RStudio only if you have associated the . RData files with RStudio.

How do I edit an RDS file in R?

rds files are serialized, you don't want to edit the file directly. Load the object, change the things you need changed and then re-save the new object.


1 Answers

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.

like image 50
user2554330 Avatar answered Oct 17 '22 22:10

user2554330