https://github.com/edwindj/rvee
Recreational V programming for R
https://github.com/edwindj/rvee
r r-package vlang
Last synced: about 1 year ago
JSON representation
Recreational V programming for R
- Host: GitHub
- URL: https://github.com/edwindj/rvee
- Owner: edwindj
- License: other
- Created: 2021-05-31T07:23:18.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2022-06-22T13:28:54.000Z (almost 4 years ago)
- Last Synced: 2025-03-31T15:27:23.853Z (about 1 year ago)
- Topics: r, r-package, vlang
- Language: Verilog
- Homepage: https://edwindj.github.io/rvee
- Size: 1.8 MB
- Stars: 8
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
README
---
output: github_document
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# `rvee`
## Recreational V programming for R / WIP
[](https://CRAN.R-project.org/package=rvee)
[](https://github.com/edwindj/rvee/actions)
**Early work! (not ready for production)**
Create R extension packages with the [V programming language](https://vlang.io).
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](https://cran.r-project.org/doc/manuals/r-release/R-exts.html#System-and-foreign-language-interfaces)
, [fortran](https://cran.r-project.org/doc/manuals/r-release/R-exts.html#System-and-foreign-language-interfaces)
, cpp (e.g. [Rcpp](http://www.rcpp.org/))
, python (e.g. [reticulate](https://rstudio.github.io/reticulate/))
and rust (e.g. [r-rust](https://github.com/r-rust)).
R Package `rvee` intends to provide an easy toolkist for creating R packages with
the `v` programming language.
## Status
Translation to `C` and compilation 🎉!
Interfacing:
- [x] Generating all interfacing code from `v` file with `rvee::rv_export_c()`
- [x] wraps simple input and return types: `f64`, `int`, `bool`, `string`
- [x] wraps `numeric`, `logical`, `integer`, `character`, `factor` and `list` input and return types.
- [x] compiling and working :-)
- [ ] wraps `data.frame` input and return types.
- [ ] wraps array input and return types: `[]f64`, `[]int`, `[]bool`, `[]string`
- [x] CRAN checks
r module (in v):
- [x] `Numeric`, direct access as a `[]f64`
- [x] `Integer`, direct access as a `[]int`
- [x] `Character`, indirect access as a `[]string`. string values of R are reused, but newly created string (not managed by R) are copied.
- [x] `Logical`, indirect access as a `[]bool`. automatically converts between `[]bool` and `logical`.
- [x] `Factor`
- [x] `List`
- [x] `DataFrame`
- [ ] `Environment`
- [ ] `Function`
## Installation
The **unstable** development version from [GitHub](https://github.com/) with:
``` r
# install.packages("devtools")
devtools::install_github("edwindj/rvee")
```
## Overview
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).
## Example
Transpiling to C works.
Put your `v` files in the `"/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/.c"`: the c code generated by `v` from the source files in the
`"/src/v"` directory.
After that `devtools::load_all` (or `R CMD SHLIB`) work: they will compile `"init.c"`
and `".c"` into `".so"`/`".dll"`.
Suppose we have the following file "/src/example.v"
```{r, eval = FALSE, results="asis", code=readLines("example/example.v")}
```
With:
```{r, eval=FALSE}
rvee::rv_export_c("", prefix="my_pkg") # is root dir of the source of your package...
```
The interfacing code is generated:
`"/src/v/rv_export.v"`:
```v
```{r, echo=FALSE, results='asis'}
fns <- rvee:::scan_v_file("example/example.v")
pkg <- "my_pkg"
rvee:::generate_rv_export_v(fns,pkg=pkg)
```
```
and
`"/R/rv_export.R"`:
```r
```{r, echo=FALSE, results='asis'}
rvee:::generate_rv_export_R(fns, pkg = pkg)
```
```
And create the shared library with a call to devtools
```{r, eval = FALSE}
devtools::load_all("")
```