[Rd] How to access to internal header files

Henrik Bengtsson henr|k@bengt@@on @end|ng |rom gm@||@com
Tue May 24 19:17:33 CEST 2022


Ramiro Magno has started the c3po package/project:

 https://rmagno.eu/c3po/

"c3po is a documentation-only package for the journey from R to C and
back again."

It documents the C-level R API using R's help system, e.g.

> library(c3po)
> ?asLogical

Rf_asLogical               package:c3po                R Documentation

Convert an R scalar logical vector to a C int

Description:

     *Function, pure* *R to C*

     Converts a scalar (length one) 'logical' vector ('SEXP') 'x' to a
     C 'int'.

Arguments:

       x: a pointer 'SEXP', referring to an object of type 'LGLSXP'.

Value:

     A C 'int' value.

Declaration:

     int asLogical(SEXP x);

     In Rinternals.h.

Definition:

     int asLogical(SEXP x)
     {
       return asLogical2(x, /* checking = */ 0, R_NilValue, R_NilValue);
     }

     In coerce.c.

Examples:

     # Convert an R length one logical vector to a C int number
     # Please note that the double backslash in "\n" in Rprintf is only required
     # because of the inlining of the code here.
     rlogical_to_cint <- inline::cfunction(c(x = "logical"),
      ' int x_;
        x_ = Rf_asLogical(x);
        Rprintf("x_ is %d\\n", x_);
        return R_NilValue;
      ')
     # NA is mapped to INT_MIN
     invisible(rlogical_to_cint(NA))

     # Empty logical is also mapped to INT_MIN
     invisible(rlogical_to_cint(NA))

     # FALSE is internally mapped to 0
     invisible(rlogical_to_cint(FALSE))

     # TRUE is internally mapped to 1
     invisible(rlogical_to_cint(TRUE))

As with all R help pages, it's renders nicely as HTML with links etc.,
if you run help.start() first.

I think this is a great effort worth contributing to:
https://github.com/ramiromagno/c3po

/Henrik

On Tue, May 24, 2022 at 8:52 AM Sokol Serguei <sokol using insa-toulouse.fr> wrote:
>
> Le 24/05/2022 à 16:59, Sebastian Fischer a écrit :
> > Thanks, It would be great to get instructions on how I can compile R, so
> > that those header files are visible and can be used when compiling
>
> "R Installation and Administration" can help
> https://cran.r-project.org/doc/manuals/r-release/R-admin.html
>
>
> > via R CMD SHLIB,
>
> If you search to compile R itself, it will be with "make ". "R CMD
> SHLIB" is rather for your own source files.
>
> Best,
> Serguei.
>
> >
> > best regards
> >
> > Sebastian Fischer
> >
> > Am Di., 24. Mai 2022 um 15:50 Uhr schrieb Dirk Eddelbuettel <edd using debian.org
> >> :
> >> On 24 May 2022 at 15:23, Martin Maechler wrote:
> >> | Well, if you want to explore how R is written ... and that's the
> >> | only good reason for looking into such private header files ...
> >> | then get the sources of R and explore...
> >> |
> >> | The official sources (and even daily snapshots from both
> >> | "R-patched" and "R-devel")  are available e.g. from
> >> |
> >> |  https://cran.r-project.org/sources.html
> >>
> >> And for those who prefer the GitHub interface (including reasonably
> >> powerful
> >> searches, now even via two APIs, as well as editor support) there are the
> >> mirrors of the svn repo at GitHub of which
> >>
> >>     https://github.com/r-devel/r-svn
> >>
> >> is the more recent variant with extra polish to better map original commits
> >> to a nicely browseable git commit history.  It also has all the branches.
> >>
> >> I still keep an svn checkout for local builds of r-devel as I have since
> >> 'forever' but find the github access extremely valuable for browsing.
> >>
> >> So a cheers for Jeroen for taking care of this.
> >>
> >> Dirk
> >>
> >> --
> >> dirk.eddelbuettel.com | @eddelbuettel | edd using debian.org
> >>
> >       [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-devel using r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-devel
>
> ______________________________________________
> R-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



More information about the R-devel mailing list