I have this code:
x <- rnorm(10)
print(x)
is returning as output:
[1] -0.67604293 -0.49002147 1.50190943 0.48438935 -0.17091949 0.39868189
[7] -0.57922386 -0.08172699 -0开发者_如何转开发.82327067 0.07005629
I suppose that R is having a limit of characters per line or something and that is why is splitting the result in 2 lines. I am building a service based on the output of R.
What should I do in order to get it in one line?
You can adjust the printing width in R by adjusting the options("width") option. If you give us more details about your project, maybe we could be of better use.
Than it is better to tell R to output things in a way that will be convenient to your wrapper; check out string functions like paste()
, sprintf()
and push the result into output with cat()
; for instance putting numbers in a column could look like:
x<-rnorm(10)
cat(paste(x,collapse="\n"),"\n")
what outputs just:
0.889105851072202
0.86920550247321
0.817785758768382
-0.0194490361401052
1.13386492568134
0.0786139738004322
0.7431631392675
0.93881227070957
0.534225167458455
1.08265812080696
Thanks to everybody for their responses. I want to publish a new way of doing it that for me was the best and maybe someone else will need this reference. As I am building a webservice I will be using phpSerialize to control the output so I can unserialize it in PHP.
library(phpSerialize)
x<-rnorm(10)
x = phpSerialize(x)
cat(x)
精彩评论