How to export dataframe to RDATA file in R?
Last Updated :
25 Nov, 2023
In this, article we are going to save the information of a data frame in an RDATA file and display the information of the file using R Programming language. To save the information of a data frame in a file and display the information of the file in R language is as follows:
- Using the save function to save the file .RData format.
- Using the load() function to load that saved.RData file
- Using the file.info() function to get the information of a particular file.
Step 1: Use the save() function to save the file.RData format
In this step user needs to call the save(), function with the name of the new file and with its format passed as its parameter, This function will simply save the file as per the user-specified parameter in the working directory.
save() function: This function writes an external representation of R objects to the specified file.
Syntax: save(…, list = character(), file = stop("'file' must be specified"),ascii = FALSE, version = NULL, envir = parent.frame(), compress = isTRUE(!ascii), compression_level, eval.promises = TRUE, precheck = TRUE)
In this example, we will be simply saving a data frame in new.RData file in the working directory.
R
gfg_data = data.frame(A = c(7,6,2,8,1),
B = c(4,2,9,7,3),
C = c(1,7,2,6,8))
print("Dataframe:->")
print(gfg_data)
save(gfg_data, file = "gfg.RData")
Output:
[1] "Dataframe:->"
A B C
1 7 4 1
2 6 2 7
3 2 9 2
4 8 7 6
5 1 3 8

Step 2: Use the load() function to load that saved.RData file
In this step user just need to call the load() function with the name of the file saved in step-1 as its parameter, further, this will help to load the save file in the console so that the user can manage the operation on this file.
Load() function: This function is used to reload datasets written with the function save.
Syntax: load(file, envir = parent.frame(), verbose = FALSE)
Parameters:
- File:-a character string giving the name of the file to load.
- envir:-the environment where the data should be loaded.
- Verbose:-should item name be printed during loading?needs
Under this example, we will be loading the.RData file using the load() function which was saved in the previous example.
R
Output:
A B C
1 7 4 1
2 6 2 7
3 2 9 2
4 8 7 6
5 1 3 8
Step3: Using file.info() function to get the information of a particular file.
This is the final step to save the information of a data frame in a file and displays its information, Here the step1 and step2 is used to save the information of the given data frame in a particular file and this step3 will be used to displaying the information of the file where the given data-frame is been saved and for this, we will be using the file.info() function with the name of the previously loaded file in the console to display the information of the file saved.
file.info() function: This is a utility function used to extract information about files on the user's file systems.
Syntax: file.info(…, extra_cols = TRUE)
Parameter:
- …:-character vectors containing file paths
- extra_cols:-Logical: return all cols rather than just the first six.
Returns: size , isdir, mode, ctime, time, atime and exe
Using the file.info() function in R language we will be displaying the completed information of the file saved and loaded in the previous examples.
R
#load("gfg.RData")
file.info("gfg.RData")
Output:
size isdir mode mtime ctime
gfg.RData 185 FALSE 666 2023-07-28 15:35:33 2023-07-28 15:29:53
atime exe
gfg.RData 2023-07-28 15:35:34 no
Similar Reads
How to Export DataFrame to CSV in R ?
R Programming language allows us to read and write data into various files like CSV, Excel, XML, etc. In this article, we are going to discuss how to Export DataFrame to CSV file in R Programming Language. Approach:Â Write Data in column wise formatCreate DataFrame for these dataWrite Data to the CS
1 min read
How to Delete DataFrames in R?
In R, a DataFrame is a data structure which can be two-dimensional, that is it can be used to hold data in rows and columns. To create a DataFrame, you can use the data.frame() function. but after you're done with a DataFrame, you may wish to remove it so that memory can be released or your workspac
3 min read
R Read Text File to DataFrame
In today's data-driven world, collecting data from multiple sources and turning it into a structured manner is a critical responsibility for data analysts and scientists. Text files are a prominent source of data, as they frequently include useful information in plain text format. To be used success
5 min read
How to Write Entire Dataframe into MySQL Table in R
In this article, we are going to learn how to write the entire data frame into a MySQL table in R programming language. To perform this task we need some basic requirements which are listed below: Install MySQLInstall R StudioBasic knowledge of SQL queries. Using SQL queries create a database "gfg_d
3 min read
Write DataFrame to SPSS .sav File in R
In this article, we are going to see how to write Dataframe to SPSS .sav File in R Programming language. The SPSS Statistics File Format is a proprietary binary format, developed and maintained as the native format for the SPSS statistical software application. To write a data frame in SPSS format i
1 min read
How to Convert Numeric Dataframe to Text in xlsx File in R
In this article, we are going to convert a numeric data frame which means the data present in both rows and columns of the data frame is of numeric type to an Excel file(.xlsx). To achieve this mechanism in R Programming, we have a package called writexl which contains the write_xlsx() function whic
2 min read
How to Convert XML to DataFrame in R?
A Data Frame is a two-dimensional and tabular data structure in the R that is similar to a table in the database or an Excel spreadsheet. It is one of the most commonly used data structures for the data analysis in R with the columns representing the various and rows representing the observations.XM
4 min read
Export Specific Columns in DataFrame to CSV File
A data frame is a tabular data structure similar to a spreadsheet. It has rows and columns. CSV (Comma-Separated Values) is a plain text file format used for storing tabular data. Each line in a CSV file represents a row of data, and the values within a line are separated by commas. This article exp
3 min read
Export Dataframes to Multiple Excel Sheets in R
An excel workbook is used to contain tabular information stored within a cell-like structure. Every excel workbook in R contains multiple sheets to contain the data belonging to the same domain information. The excel sheet can contain columns belonging to different data types. The Excel files can be
5 min read
How to import an Excel File into R ?
In this article, we will discuss how to import an excel file in the R Programming Language. There two different types of approaches to import the excel file into the R programming language and those are discussed properly below. File in use: Method 1: Using read_excel() In this approach to import th
3 min read