0

I might just be crazy but I really can't see where I am going wrong on my simple R program. I am trying to read a table from a file but every time I try to it comes back with this error:

./tmp.r: line 1: syntax error near unexpected token `('
./tmp.r: line 1: `tmp <- read.table("/home/Data/run1.DOC.sample_summary",header=FALSE)'

The file I am trying to read from looks something like this:

Aim  A_%_above_20  A_%_above_30  A_%_above_40  
28         0.0          0.0          0.0     
99         50           100.0        82.9  
34         62.1         0.0          0.0  

Here is my code:

tmp <- read.table("/home/Data/run1.DOC.sample_summary",header=FALSE)
names(tmp)
max_num <- max(tmp)
hist(tmp$'*_%_above_30',col=heat.colors(max_num), main='Percent in Test', xlab='Percent Covered')

Does anyone see what I am doing wrong here? I am just not seeing it. Thanks

Stephopolis
  • 1,765
  • 9
  • 36
  • 65
  • As a rule I try to make my column names "propper" from an R perspective before I read the data in. In this case, R doesn't like th e `%` symbol. I'd suggest using a command line tool like `sed` or going in manually and changing the header row and trying again. You can also try `read.table(..., skip=1, header=FALSE)`. – Justin Jul 25 '12 at 14:45
  • When I copy+paste your example file into a text file, I am able to read it just fine (although I'm not sure why you would want to specify `header = FALSE`; that seems wrong to me). R will by default remove the `%` signs, but that shouldn't cause an error. You probably have some other strange character in your file. – joran Jul 25 '12 at 15:08

2 Answers2

0

it this because you used wrong path name? e.g., try changing "home..." to "/home..."

0

Those tmp$'*_%_above_30' really work in your last line ?

Also, try to put comments on different part of your code to see which one is making your code crash.

Finally, maybe it's just a bad encoding of some characters in your code. Try to rewrite it from scratch.

And how do you launch your script ?

BaL
  • 93
  • 1
  • 8
  • I am attempting to do it from command line. Previously when I have used R it was with a gui but that isn't available on where I am working from here – Stephopolis Jul 25 '12 at 14:48
  • Also, I have no idea if that line works or not. I was just giving it a go. I haven't managed to get past the first line even. Lol – Stephopolis Jul 25 '12 at 14:49
  • 1
    So try to remove all the lines except the first one, see if that solves your problem. Then to launch your code, what command are you using ? Try `R -f tmp.r` – BaL Jul 25 '12 at 14:53
  • Ahhhhhh. My command was wrong I guess? I didn't include the -f. Also just for future reference that line of code doesn't work, but that is something I haven't even tried to play with yet. So thank you. – Stephopolis Jul 25 '12 at 15:16