tidycpp

Tidy C++ wrapping of the C API of R

https://github.com/eddelbuettel/tidycpp

Science Score: 13.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
  • DOI references
  • Academic publication links
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (11.4%) to scientific vocabulary

Keywords

cpp cran r r-package
Last synced: 6 months ago · JSON representation

Repository

Tidy C++ wrapping of the C API of R

Basic Info
  • Host: GitHub
  • Owner: eddelbuettel
  • Language: C++
  • Default Branch: master
  • Homepage:
  • Size: 124 KB
Statistics
  • Stars: 40
  • Watchers: 4
  • Forks: 3
  • Open Issues: 0
  • Releases: 0
Topics
cpp cran r r-package
Created over 5 years ago · Last pushed over 1 year ago
Metadata Files
Readme Changelog

README.md

tidyCpp: Tidy C++ wrapping of the C API for R

CI License CRAN Dependencies Downloads Last Commit

About

The C API of the R language and environment is robust, yet a little awkward for C++ programmers. This package wraps a tidy layer of header functions around it.

R Core is moving towards a more explicit classification of which functions are officially part of the API for R, and which ones are 'experimental'. A very helpful contributed page summarizes the status.

Examples

A recent motivating example is from the dang package which includes one unexported Base R function written in C. The original version is here. While short enough, we found working with a tidier version easier and more enjoyable. We include an abbreviated version (minus the copyright header) here:

```c++

include

extern "C" {

// cf src/library/tools/src/text.c SEXP checknonASCII(SEXP text, SEXP ignorequotes) { /* Check if all the lines in 'text' are ASCII, after removing comments and ignoring the contents of quotes (unless ignorequotes) (which might span more than one line and might be escaped).

   This cannot be entirely correct, as quotes and \ might occur as
   part of another character in a MBCS: but this does not happen
   in UTF-8.
*/
int i, nbslash = 0; /* number of preceding backslashes */
const char *p;
char quote= '\0';
Rboolean ign, inquote = FALSE;

if (!R::isString(text)) R::error("invalid input");
ign = (Rboolean) R::asLogical(ignore_quotes);
if (ign == NA_LOGICAL) R::error("'ignore_quotes' must be TRUE or FALSE");

for (i = 0; i < R::length(text); i++) {
    p = R::charPointer(R::stringElement(text, i)); // ASCII or not not affected by charset
    inquote = FALSE; /* avoid runaway quotes */
    for (; *p; p++) {
        if (!inquote && *p == '#') break;
        if (!inquote || ign) {
            if ((unsigned int) *p > 127) {
                Rprintf("%s\n", R::charPointer(R::stringElement(text, i)));
                Rprintf("found %x\n", (unsigned int) *p);
                return R::scalarLogical(TRUE);
            }
        }
        if ((nbslash % 2 == 0) && (*p == '"' || *p == '\'')) {
            if (inquote && *p == quote) {
                inquote = FALSE;
            } else if(!inquote) {
                quote = *p;
                inquote = TRUE;
            }
        }
        if (*p == '\\') nbslash++; else nbslash = 0;
    }
}
return R::scalarLogical(FALSE);

}

} // extern "C" ```

Additions from the tidyCpp wrapper can be identified easily via the R:: namespace. While the code is not hiding its C heritage, we find it overall a little easier to work with. Other examples (see below) show how using tidyCpp can help avoid the very manual and error-prone PROTECT and UNPROTECT and pairs.

For additional examples, please see the Motivation vignette for a longer discussion with more examples, and the files in the snippets/ directory for directly callable code examples.

Author

Dirk Eddelbuettel

License

GPL (>= 2)

Owner

  • Name: Dirk Eddelbuettel
  • Login: eddelbuettel
  • Kind: user
  • Location: Chicago, IL, USA

GitHub Events

Total
  • Watch event: 1
  • Push event: 1
Last Year
  • Watch event: 1
  • Push event: 1

Committers

Last synced: 11 months ago

All Time
  • Total Commits: 73
  • Total Committers: 1
  • Avg Commits per committer: 73.0
  • Development Distribution Score (DDS): 0.0
Past Year
  • Commits: 4
  • Committers: 1
  • Avg Commits per committer: 4.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Dirk Eddelbuettel e****d@d****g 73
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 1
  • Total pull requests: 1
  • Average time to close issues: 2 days
  • Average time to close pull requests: 9 minutes
  • Total issue authors: 1
  • Total pull request authors: 1
  • Average comments per issue: 2.0
  • Average comments per pull request: 3.0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 0
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 0
  • Average comments per issue: 0
  • Average comments per pull request: 0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • romainfrancois (1)
Pull Request Authors
  • romainfrancois (1)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • cran 381 last-month
  • Total docker downloads: 48
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 7
  • Total maintainers: 1
cran.r-project.org: tidyCpp

Tidy C++ Header-Only Definitions for Parts of the C API of R

  • Versions: 7
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 381 Last month
  • Docker Downloads: 48
Rankings
Stargazers count: 8.1%
Forks count: 12.8%
Average: 24.5%
Dependent packages count: 29.8%
Dependent repos count: 35.5%
Downloads: 36.2%
Maintainers (1)
Last synced: 6 months ago

Dependencies

DESCRIPTION cran
  • Rcpp * suggests
  • RcppSpdlog * suggests
  • simplermarkdown * suggests
.github/workflows/ci.yaml actions
  • actions/checkout v3 composite