How to export dataframe to RDATA file in R ?
In this, article we are going to save the information of a data frame in a 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 in.RData format.
- Using the load() function to load that saved.RData file
- Using file.info() function to get the information of a particular file.
Step 1: Using the save() function to save the file in.RData format
In this step user need 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.
Step 2: Using 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)
- 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?
Under this example, we will be loading the .RData file using load() function which was saved in the previous example.
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)
- …:-character vectors containing file paths
- extra_cols:-Logical: return all cols rather than just the first six.
The complete information of the file including – size, mode, ctime, exe, time, atime, and isdir.
Using the file.info() function in R language we will be displaying the completed information of the file save and loaded in the previous examples.
Please Login to comment...