controlling R output

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?

Answers


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

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.


Need Your Help

How to generate all permutations of a list in Python

python algorithm permutation combinatorics python-2.5

How do you generate all the permutations of a list in Python, independently of the type of elements in that list?

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.