A proof-of-concept package documenting the R Native API via the built-in R help system. The help pages are written in Roxygen2 that are compiled to Rd format and then rendered by R as regular help pages.
Disclaimer: This is just a proof of concept; I’m not claiming this is the best approach.
> options(help_type = "text")
> ?RNativeAPI::getAttrib
:RNativeAPI R Documentation
getAttrib package
Gets and Sets an Attribute of an R Object
:
Description
Gets and Sets an Attribute of an R Object
:
Usage
getAttrib(vec, name)
setAttrib(vec, name, val)
:
Arguments
: (SEXP) An R object.
vec
: (SEXP) A character of length one.
name
: (SEXP) An R object.
val
:
Value
getAttrib() returns (SEXP) the value of attribute ‘name’.
setAttrib() returns (SEXP) a copy of R object ‘vec’ with attribute ‘name’ set.
:
C API
getAttrib(SEXP vec, SEXP name)
SEXP setAttrib(SEXP vec, SEXP name, SEXP val)
SEXP
:
R API
<- attr(vec, name)
value attr(vec, name) <- val
:
Source
: src/include/Rinternals.h
Declaration
: src/main/attrib.c Implementation
> RNativeAPI::getAttrib
function (vec, name)
{= SEXP
vec = SEXP
name return(SEXP)
}<bytecode: 0x561c1cd594c0>
<environment: namespace:RNativeAPI>
Comment: By a customized class and print()
method, the above can probably be presented much nice. With some efforts, it could even display the actual source code (there are already R packages providing functionalities for this).