https://github.com/kxsystems/embedr
Embedding R inside q
https://github.com/kxsystems/embedr
embedr interface kdb q r
Last synced: 3 months ago
JSON representation
Embedding R inside q
- Host: GitHub
- URL: https://github.com/kxsystems/embedr
- Owner: KxSystems
- License: apache-2.0
- Created: 2017-11-09T13:41:29.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2024-12-06T14:57:08.000Z (7 months ago)
- Last Synced: 2025-04-12T03:14:12.542Z (3 months ago)
- Topics: embedr, interface, kdb, q, r
- Language: C
- Homepage: http://code.kx.com/q/interfaces
- Size: 205 KB
- Stars: 11
- Watchers: 5
- Forks: 11
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# embedR: Embedding R inside q
A KX [Fusion interface](https://code.kx.com/q/interfaces)
## Installation
### Download
Download the appropriate release archive from [releases](../../releases/latest) page.### Unpack and install content of the archive
environment | action
----------------|---------------------------------------------------------------------------------------
Linux | `tar xzvf embedr_linux-v*.tar.gz -C $QHOME --strip 1`
macOS | `tar xzvf embedr_osx-v*.tar.gz -C $QHOME --strip 1`
Windows | Open the archive and copy content of the `embedr` folder (`embedr\*`) to `%QHOME%` or `c:\q`
Copy `R_HOME/x64/*.dll` or `R_HOME/i386/*.dll` to `QHOME/w64` or `QHOME/w32` respectively.## Calling R
When calling R, you need to set `R_HOME`. Required are:
```bash
# Linux/macOS
export R_HOME=`R RHOME`
# Windows
for /f "delims=" %a in ('R RHOME') do @set R_HOME=%a
```The library has four main methods:
- `Ropen`: Initialise embedded R. Optional to call. Allows to set verbose mode as `Ropen 1`.
- `Rcmd`: run an R command, do not return a result
- `Rget`: run an R command, return the result to q
- `Rset`: set a variable in the R memory space### Interactive plotting
If using interactive plotting with `lattice` and/or `ggplot2` you will need to call `print` on a chart object.
## Examples
See [examples](examples) folder.
Note: Examples are kdb+ 3.5 or higher.
### Example 1
`e4.q` is a simple example of plot 'moving window volatility' of returns. Converted from http://www.mayin.org/ajayshah/KB/R/html/p4.html
### Example 2
`pcd.q` is based on [Corporate credit card transactions 2014-15](https://data.gov.uk/dataset/corporate-credit-card-transaction-2014-15).
Download CSV from the link above and save it in the same folder as `pcd.q` under name `pcd2014v1.csv`.
### Example 3
Left for the reader :wink:
## Documentation
* [User guide](docs/README.md)
* [Using R with kdb+](docs/r-and-q.md)
* [Examples using rkdb/embedR](docs/examples.md)
* [Other methods](docs/other-methods.md)