Skip to content
Prev 181423 / 398502 Next

Help needed on R output

peng chen wrote:
Hi Peng and others,
I assumed that you wanted to generate that (Pascal?) expression and you 
have a character or binary numeric vector of the six elements. Say that 
vector is named "binaryvector".

cat("rom_array := (\n")
ends<-c(rep("\",\n",5),"\")\n")
for(i in 1:length(binaryvector))
 cat("\"",binaryvector[i],ends[i],sep="")

should do what you want. However, I have two questions:

1) Why does cat put a newline at the end of a call with a sep argument 
with a newline in it? It doesn't put the sep argument after the last 
element of the vector, even though the help page says that it does.

2) The help page reads:

sep   a character vector of strings to append after each element.

but cat clearly uses only the first string of the vector. Am I reading 
this wrongly?

Jim