knitr::opts_chunk$set( collapse = TRUE, comment = "#>", fig.path = "man/figures/README-", out.width = "100%" )
rvee
Early work! (not ready for production)
Create R extension packages with the V programming language. V is a simple, safe and fast programming language with the speed of C.
R has good interfaces for many programming languages such as C
, fortran
, cpp (e.g. Rcpp)
, python (e.g. reticulate)
and rust (e.g. r-rust).
R Package rvee
intends to provide an easy toolkist for creating R packages with
the v
programming language.
Translation to C
and compilation 🎉!
Interfacing:
v
file with rvee::rv_export_c()
f64
, int
, bool
, string
numeric
, logical
, integer
, character
, factor
and list
input and return types.data.frame
input and return types.[]f64
, []int
, []bool
, []string
r module (in v):
Numeric
, direct access as a []f64
Integer
, direct access as a []int
Character
, indirect access as a []string
. string values of R are reused, but newly created string (not managed by R) are copied.Logical
, indirect access as a []bool
. automatically converts between []bool
and logical
.Factor
List
DataFrame
Environment
Function
The unstable development version from GitHub with:
# install.packages("devtools") devtools::install_github("edwindj/rvee")
Possible routes for creating an R extension with v
code are:
a) Transpiling V
code to C
code and use it as a normal C
extension.
b) Using the v
compiler to build a shared library linked to the R shared library.
Both options have their benefits and draw backs:
a) Allows for easy distribution and installation, but requires tweaking the compilation flags to pass CRAN checks etc. and removing/stripping code that is not needed by R.
b) Allows for an optimized shared library, but requires v
to be installed by the
installer (e.g. CRAN).
Transpiling to C works.
Put your v
files in the "<pkg>/src/v"
directory and decorate each function to be
exported with the [rv_export]
attribute (see example below).
After that
rvee::rv_export_c
generates the necessary interfacing code:
"./R/rv_export.R"
: R functions calling the v functions declared in "./src/v/rv_export.v"
"./src/v/rv_export.v"
: v wrapper functions translating input and output to the original v functions."./src/init.c"
: registration code for the shared library"./src/<pkg>.c"
: the c code generated by v
from the source files in the
"<pkg>/src/v"
directory.After that devtools::load_all
(or R CMD SHLIB
) work: they will compile "init.c"
and "<pkg>.c"
into "<pkg>.so"
/"<pkg>.dll"
.
Suppose we have the following file "
With:
rvee::rv_export_c("<pkg>", prefix="my_pkg") # <pkg> is root dir of the source of your package...
The interfacing code is generated:
"<pkg>/src/v/rv_export.v"
:
```r fns <- rvee:::scan_v_file("example/example.v") pkg <- "my_pkg" rvee:::generate_rv_export_v(fns,pkg=pkg)
and `"<pkg>/R/rv_export.R"`: ```r ```r rvee:::generate_rv_export_R(fns, pkg = pkg)
And create the shared library with a call to devtools ```r devtools::load_all("<pkg>")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.