user2939281
user2939281

Reputation: 117

How to read a data table into R as a matrix

This code is directly from a Bioconductor vignette for creating an expressionSet (http://www.bioconductor.org/packages/2.12/bioc/vignettes/Biobase/inst/doc/ExpressionSetIntroduction.pdf).

>  exprs <- as.matrix(read.table(exprsFile, header=TRUE, sep = "\t",
                 + row.names = 1,
                 + as.is=TRUE))

Can anyone tell why this code generates the following error message?

> exprs <- as.matrix(read.table(exprsFile, header=TRUE, sep = "\t",
+                       row.names = 1,
Error: unexpected '=' in:
"exprs <- as.matrix(read.table(exprsFile, header=TRUE, sep = "\t",
                 + row.names ="
>                      + as.is=TRUE))
Error: unexpected ')' in "                     + as.is=TRUE)"

Or, could you suggest an alternative method to read in the file exprsFile as a matrix with header?

Thank you very much for your time.

Upvotes: 10

Views: 38328

Answers (1)

mnel
mnel

Reputation: 115392

The biobase vignette is (almost certainly) produced using Sweave. The > and leading + where single expressions have been split over multiple lines are an artefact of using Sweave and how it displays code it processes. It reflects how the terminal / console (R session) would looked if you had entered the following (which should work)

exprs <- as.matrix(read.table(exprsFile, header=TRUE, sep = "\t",
                  row.names = 1,
                  as.is=TRUE))

knitr (which is an alternative to Sweave, and is now permitted for vignettes, by default has these prompts removed, so code is more directly copy-and-pastable.

Upvotes: 16

Related Questions