Convert CSV to RDS format of data files when using R can make your project easier, because *.rds is R’s native format (the way *.sas7bdat is SAS’s native format). Often, when doing a research project, you receive data files in *.csv format. In R GUI, it is easy to import a CSV. It’s so easy that often, if you are doing a whole project in R, you might just keep all your imported and exported data from the project in CSV format, and never convert CSV to RDS.
But if you are using large data files, or CSVs that are giving R GUI some trouble (especially with headers), it can be nice to read the CSV into R, but then for the purpose of the project, convert CSV to RDS, and export it as an RDS file – and then from then on, only export RDS files for data for the project. You will find I do that with datasets from BRFSS when I use R because those datasets are so big, and once I convert them to RDS, R handles them more efficiently.
I made videos for each of these steps I can show you here, with code available on Github.
Convert CSV to RDS first Requires Importing CSV into R
Whenever you convert a CSV to a native software format (e.g., converting a CSV in SAS to a *.sas7bdat file, or converting a CSV in SPSS to a *.sav file), you have to start by importing the CSV into the software of choice. This time the software of choice is R GUI, so the first step is to import the dataset into R GUI, which is what is demonstrated in this video.
Next, Export the RDS File from R
Once the file has been imported into the software of choice, you can now export it in the native format of the software. In R GUI, that means that once we import the CSV into the R GUI environment, we can now export it as an RDS into whatever data folder we have mapped for the session. This video gives a demonstration of doing this.
To Verify the Export, Now Import the RDS into R
Sometimes there can be issues with conversion. For example, I have imported CSVs before into R where the header on the CSV shows up differently in R (e.g., with some trailing characters that are not in the native file). I don’t know what that happens. I get other oddities from time to time.
This is why I always want to make sure that the native CSV which was given to me is represented authentically in the RDS file I’m making in R. So, once I export the RDS, I want to import the RDS and compare it with the original CSV. That way, I can make sure all the data landed properly, because then I can use this RDS version for the rest of the project.
Added Github link on October 12, 2022.
Convert CSV to RDS is what you want to do if you are working with big data files in R GUI and want to improve efficiency. Read my blog post for an explanation and video demonstrations of this process!