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
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (13.4%) to scientific vocabulary
Keywords
Repository
Easily compile inline C code for R
Basic Info
- Host: GitHub
- Owner: coolbutuseless
- License: other
- Language: R
- Default Branch: main
- Homepage: https://coolbutuseless.github.io/package/callme/index.html
- Size: 817 KB
Statistics
- Stars: 23
- Watchers: 4
- Forks: 0
- Open Issues: 1
- Releases: 0
Topics
Metadata Files
README.md
callme 
{callme} compiles inline C code and generates wrappers so that the C
code can be easily called from R.
Features:
- Compile inline C code (or code from a file) and makes it immediately (and easily!) available to R.
- Accepts complete C code - including function declaration and header
#includedirectives. - Explicit handling for
CFLAGS,PKG_CPPFLAGSandPKG_LIBSfor setting compiler flags, C pre-processor flags, and library linking flags, respectively. - Generates R functions to call the compiled C functions.
- Multiple function definitions allowed in a single code block.
What’s in the box
compile(code, CFLAGS, PKG_CPPFLAGS, PKG_LIBS, env, verbosity)compile the Ccodeand assign R functions into the nominatedenvin R. C code could be as a string or in a file.
Installation
This package can be installed from CRAN
r
install.packages('callme')
You can install the latest development version from GitHub with:
``` r
install.package('remotes')
remotes::install_github('coolbutuseless/callme') ```
Pre-built source/binary versions can also be installed from R-universe
r
install.packages('callme', repos = c('https://coolbutuseless.r-universe.dev', 'https://cloud.r-project.org'))
Example
The following example compiles a code snippet into a C library and creates a wrapper function in R (of the same name) which can be used to call the compiled code.
``` r library(callme)
code <- "
include
include
// Add 2 numbers SEXP add(SEXP val1, SEXP val2) { return ScalarReal(asReal(val1) + asReal(val2)); }
// Multiply 2 numbers SEXP mul(SEXP val1, SEXP val2) { return ScalarReal(asReal(val1) * asReal(val2)); }
// sqrt elements in a vector SEXP newsqrt(SEXP vec) { SEXP res = PROTECT(allocVector(REALSXP, length(vec))); double *resptr = REAL(res); double *vecptr = REAL(vec); for (int i = 0; i < length(vec); i++) { resptr[i] = sqrt(vec_ptr[i]); }
UNPROTECT(1); return res; } "
compile the code
compile(code)
Call the functions
add(99.5, 0.5) ```
#> [1] 100
r
mul(99.5, 0.5)
#> [1] 49.75
r
new_sqrt(c(1, 4, 25, 999))
#> [1] 1.00000 2.00000 5.00000 31.60696
Linking against an installed library
In this example we want to get the version of the zstd library (which
has already been installed on the computer), and return it as a
character string.
We need to tell R when compiling the code:
- to look in the
/opt/homebrew/includedirectory forzstd.h. - to look for the actual
zstdlibrary in/opt/homebrew/lib. - to link to the
zstdlibrary (-lzstd)
Note: This code works for zstd installed via homebrew on macOS.
Paths will be different for other operating systems.
``` r code <- r"(
include
include
include "zstd.h"
SEXP zstdversion() { return mkString(ZSTDversionString()); } )"
Compile the code
compile(code, PKGCPPFLAGS = "-I/opt/homebrew/include", PKGLIBS = "-L/opt/homebrew/lib -lzstd")
Call the function
zstd_version() ```
#> [1] "1.5.6"
References
- Hadley’s R internals.
- Advanced R Book has a specfic chapter or R’s interface to C.
- Ella Kay’s UserR2024 conference presentation: “C for R users”
- Book: Deep R Programming
- Davis Vaughan’s Now you C me
- c3po
- R Native API
R project official documentation
- Writing R extensions Section 5 System and foreign language interfaces
- R internals
Owner
- Name: mikefc
- Login: coolbutuseless
- Kind: user
- Location: Australia
- Website: coolbutuseless.github.io
- Repositories: 23
- Profile: https://github.com/coolbutuseless
Cool, but useless.
GitHub Events
Total
- Issues event: 2
- Watch event: 6
- Push event: 2
Last Year
- Issues event: 2
- Watch event: 6
- Push event: 2
Issues and Pull Requests
Last synced: 10 months ago
All Time
- Total issues: 7
- Total pull requests: 0
- Average time to close issues: 14 days
- Average time to close pull requests: N/A
- Total issue authors: 2
- Total pull request authors: 0
- Average comments per issue: 0.57
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 1
- Pull requests: 0
- Average time to close issues: 3 months
- Average time to close pull requests: N/A
- Issue authors: 1
- Pull request authors: 0
- Average comments per issue: 0.0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- coolbutuseless (6)
- Beliavsky (1)
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- cran 198 last-month
- Total dependent packages: 0
- Total dependent repositories: 0
- Total versions: 2
- Total maintainers: 1
cran.r-project.org: callme
Easily Compile and Call Inline 'C' Functions
- Homepage: https://github.com/coolbutuseless/callme
- Documentation: http://cran.r-project.org/web/packages/callme/callme.pdf
- License: MIT + file LICENSE
-
Latest release: 0.1.11
published over 1 year ago
