Skip to content

Approach to avoid capture.output #26

Description

@cfhammill

Basically inconsequential suggestion, but I was curious how your package worked and I noticed the capture.output(print(fun)) line in read_docstring,
https://github.com/Dasonk/docstring/blob/master/R/read_docstring.R#L17

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).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions