How to disable R from changing the “-” character into '.' character when writing to a file?

I want to write the results of a table into a file and names of my columns contain the '-' character, but when I write it to a file it replaces all the '-' by a '.'.

  for(i in 1:length(Result[,1]))


do any one know how to disable this option? my coloms names are names of proteins some of them are writen in this way YER060W-A Thank you in advance.


It takes special care to make such an entity. But then you can use the col.names argument and assign colnames(dfrm) to it.

> tst <- data.frame(`a-b`= letters[1:10], `1-2`=1:10, check.names=FALSE)
> colnames(tst)
[1] "a-b" "1-2"
> write.table(tst, file="tst.txt", col.names=colnames(tst) )

Pasted from my editor:

"a-b" "1-2"
"1" "a" 1
"2" "b" 2  snipped the rest...

No success with write.table? I see that write() doesn't have the same repertoire of options as write.table. Let's make an array (rather than a dataframe) with dim names having "-"'s:

DCtest <- array(1:27, c(3,3,3))
dimnames(DCtest) <- list(dim1 =c(a="a-b",b="b-c",c="c%d"), 
                         dim3= letters[7:9])

One quick way to get output is just capture.output():

capture.output(DCtest, file="testm.txt")

testm.txt now looks like this in an editor:

, , dim3 = g

dim1  d e f
  a-b 1 4 7
  b-c 2 5 8
  c%d 3 6 9

, , dim3 = h

dim1   d  e  f
  a-b 10 13 16
  b-c 11 14 17
  c%d 12 15 18

, , dim3 = i

dim1   d  e  f
  a-b 19 22 25
  b-c 20 23 26
  c%d 21 24 27

You also should not forget that capture output has an append= parameter if you wanted to append successive slices through an array.

Need Your Help

jQuery addClass with twitter bootstrap text field

jquery css twitter-bootstrap addclass

A friend and I are building a jQuery Form Creator/Validator plugin, and we are also using twitter bootstrap because of its beautiful css elements!

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.