Skip to content
Prev 285088 / 398502 Next

Reading in csv with footer

That prints nicely, but the first column in the
result got turned into a factor:
  > d <- head(read.csv(textConnection(Lines)), -1)
  > str(d)
  'data.frame':   3 obs. of  3 variables:
   $ label_1: Factor w/ 4 levels "1","2","3","Total Rows: 3": 1 3 2
   $ label_2: int  2 2 3
   $ label_3: int  3 4 4
(Remove the call to head and you will see why.)

You could use head(,-1) on the output of readLines so
read.csv never sees the last value:
  > d2 <- read.csv(textConnection(head(readLines(textConnection(Lines)), -1)))
  > str(d2)
  'data.frame':   3 obs. of  3 variables:
   $ label_1: int  1 3 2
   $ label_2: int  2 2 3
   $ label_3: int  3 4 4
or you could use a pipe connection that called the shell script.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com