Skip to content

R Expr II: Read data

Bioinformatics Core Facility Gothenburg edited this page Sep 4, 2017 · 3 revisions

All installed packages are saved in the same place, each one in a separate folder. In the estrogen package folder there is a folder called extdata where the Affymetrix data that we will use is stored. This is where we will read our data, but not work with it.

  1. Use the function system.file() to locate this folder and save the path into a variable that you call readdir

    readdir <- system.file("extdata", package = "estrogen")

  2. Create a new folder on your computer where you will save this exercise. Use setwd() to set this folder to your current working directory.

  3. Open a new R-script file in R and save it in this directory.

You can use the dir() function to look at what is in the current working directory. Also, you can use another file path as argument in dir() to look at another directory.

  1. Use dir() to take a look at what files are in your current working directory and in the “extdata” folder.

All files with a .cel ending are data files, and the targLimma.txt file is our targets file. You can go to this directory in windows Explorer (or a similar file manager on other operating systems) and open targLimma.txt in a text editor to see how it looks.

  1. Now use the readTargets() function to read the targets file, and save it as a variable called targets. The file is already in a nice format, so all you need to input is the path to the file (which you stored in the variable readdir) and the name of the targets file. Use the help file for readTargets() if you don't know how to write the arguments.

  2. Take a look your targets object to learn what information is included.

We will now read all the data into R. Since we work with Affymetrix data we use the ReadAffy() function from the affy package. You will need to input a vector of filenames (using the filenames argument) and a path to the data files (using the celfile.path argument). By default the samples get the same names as the data files, but since you have a sample name vector in the targets data frame you can use this together with the sampleNames argument to give the samples proper names. Picking file names and sample names from the same data frame makes sure that they are in the same order.

  1. Read in the data using the ReadAffy() function, and store it in an object called rawData.

Clone this wiki locally