-
-
Notifications
You must be signed in to change notification settings - Fork 209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added operator<<() and print() functions to Vector #361
Conversation
(I think I said free function |
Whichever is fine by me. It's just moving a little code around. |
Just a very simple question: have you ever tried to print the https://github.com/RcppCore/Rcpp/blob/master/inst/include/Rcpp/vector/Matrix.h#L28 |
Just Vectors. I can add Matrix printing, but it wouldn't use the vector pattern because with Matrix alignment would matter. |
I see....because Matrix "is a" Vector. I think the proper solution here is to add a specialized Matrix printing routine then it just doesn't happen that a Matrix gets printed through the operators meant for Vectors (in the strict sense). |
Why not just implement a safe wrapper around |
Can we (easily) catch what And yes, we surely want Matrix methods too. |
Agree with @eddelbuettel that if we do it in a C++ way with streams we get the added benefits of file streams, string streams, etc. So here's what I'm thinking for For For For |
I agree with kevin, this is a wheel that does not need to be reinvented. |
Point taken re Would still be nice to a) have |
Then it would seem that we're out on |
Or have both after all? It is really an oversight not to offer |
There is one small caveat with using
This index is, of course, 1 based whereas usage in So it's a little misleading (though not horrible). |
Additionally, has anyone ever looked into capturing the output of Additionally, even if one can capture the output (temporarily) headed for |
Fair point re thread-safeness, but there is only so and so much you can do against silly programmers. If someone invokes parallel code and printing method well then they get what they deserve... |
So. There exists a free function It can, of course, be changed. Just let me know what should be done. |
It will be very interesting if you try to print it out in gdb. http://stackoverflow.com/questions/28073624/displaying-elements-of-rcppnumericmatrix-from-gdb |
I think for gdb use your best bet is |
It would be easy enough to use capture.output( print(x) ) and then print that to whatever stream afterwards |
This looks fine to me, but I still think that it would be best to implement a safe wrapper around Either way I'm comfortable accepting the PR. |
Ok, with this and the parallel email discussion this is good to go. We could of course do a |
Added operator<<() and print() functions to Vector
For issue #239, added
operator<<()
functions for theRcpp::Vector
class. These print a space delimited list of items. In the case of aCharacterVector
, each item is enclosed in"
.Additionally added a
Vector::print(const std::string comment, std::ostream &stream)
function at Dirk's behest. This function prints as follows:Unit tests are included and pass.