0

I am trying to access the source-code of R base functions like match.arg INCLUDING possible comments.

I found out that this information is contained in the attributes of an object under the name srcref

However the match.arg function does not have attributes:

attributes(match.arg)
#> NULL

My question is: Why does the base function match.arg not have attributes?

Sebastian
  • 865
  • 5
  • 13
  • 3
    It would be nice if you would show your source for this info... it sounds very suspect. Perhaps someone is confused about the `?srcref` function? That function can be useful when dealing with R files, and can create a `"srcref"` attribute, but doesn't apply to loaded. There is no mention of `srcref` or `attributes` in the old question [How do I see source code with comments?](https://stackoverflow.com/q/18005488/903061). – Gregor Thomas Dec 20 '19 at 17:00
  • Does this answer your question? [How can I view the source code for a function?](https://stackoverflow.com/questions/19226816/how-can-i-view-the-source-code-for-a-function) – M-- Dec 20 '19 at 17:45
  • I don't think you can get the source code of functions that are not directly sourced (with `source()`, `devtools::`, or related methods). Notably, I don't think any base function or one loaded with `library` is going to give you that view of the source. Whenever I want to look for comments or surrounding, I normally resort to wch's [r-source](github.com/wch/r-source) repo, though it can take a while to find a particular function. In this case, I think https://github.com/wch/r-source/blob/5a156a0865362bb8381dcd69ac335f5174a4f60c/src/library/base/R/match.R#L41 is what you asked for. – r2evans Dec 20 '19 at 20:48

0 Answers0