I had guessed prior that it would be an application of body but that doesn't return the comments. So I dug around to figure out where print is finding the source code and I noticed it's in the function's attributes
as.character(attr(f, "srcref"))
This would avoid ever hitting the output stream. And would also work for function objects with overloaded print methods (not that those are very common).
Basically inconsequential suggestion, but I was curious how your package worked and I noticed the
capture.output(print(fun))
line inread_docstring
, https://github.com/Dasonk/docstring/blob/master/R/read_docstring.R#L17I had guessed prior that it would be an application of
body
but that doesn't return the comments. So I dug around to figure out whereprint
is finding the source code and I noticed it's in the function's attributesThis would avoid ever hitting the output stream. And would also work for function objects with overloaded print methods (not that those are very common).