5.3 Create a CSV file

Before we create or save any data files on our local computer, we should first create a directory (folder) called “rawdata” to store them.

Let’s create the new directory in our “BIOL202_tutorials” working directory. To do this, use the dir.create function in R, as follows:

dir.create("rawdata")

Once you run this code, you’ll see the new directory appear in the Files pane in the bottom-right of RStudio. It might look something like this:

View of files with rawdata folder

Figure 5.2: View of files with rawdata folder

The folder is called “rawdata” because the data stored there will be the unedited, raw version of the data, and any files therein should NOT be altered. Any changes or edits one makes to the datasets should be saved in new data files that are saved in a different folder called “output”, which we’ll create later.

Let’s create a data file to work with.

Steps to create and save a CSV file

  • Open up Excel or any other spreadsheet software and enter values in the spreadsheet cells exactly as shown in the Excel example in Figure 10.1 from the Tidy Data section above
  • You should have one row with the 3 variable names (“Site”, “Day”, “Trout_Caught”), one in each column, then nine rows of data
  • Save the file as a CSV file by selecting (MAC) File > Save As > and in the drop down list: CSV UTF-8 (Comma separated), and Windows File > Save as type > CSV UTF-8 (comma separated)
  • Name it “trout.csv”, and save it within the newly created “rawdata” folder

Now we’re ready to try importing the data into a “tibble”.