Rmath - The R Standalone Math Library
The repository contains the R standalone Math Library, built to be used with the Statslabs.Stats C++ library.
Installation on Ubuntu / macOS
- Clone the repository.
git clone git@github.com:statslabs/rmath.git
- Configure the project.
cd rmath mkdir build && cd build cmake ..
- Compile and install the library.
make make install
Example program
demo.c
:
#include <stdio.h>
#include "Rmath.h"
int main() {
double shape1, shape2, prob;
printf("Enter first shape parameter: ");
scanf("%lf",&shape1);
printf("Enter second shape parameter: ");
scanf("%lf",&shape2);
printf("Enter probability level: ");
scanf("%lf",&prob);
printf("Critical value is %lf\n",qbeta(prob,shape1,shape2,1,0));
return 0;
}
Integration of Rmath in your own project
To make the project simple enough, we will create a CMake project for demo.c
.
-
Make a project folder.
mkdir example && cd example
-
Create
demo.cc
andCMakeLists.txt
in the project folder where fileCMakeLists.txt
should look like:cmake_minimum_required(VERSION 3.0) project(example) add_executable(example demo.c) find_package(Rmath 1.0.0 REQUIRED) target_link_libraries(example Rmath::Rmath)
-
Perform a out-of-source build.
mkdir build && cd build cmake .. make
-
Run the program.
./example
A quick check on whether the program works:
Enter first shape parameter: 1.5 Enter second shape parameter: 0.3 Enter probability level: .10 Critical value is 0.478398
This corresponds to the following call in R:
> qbeta(.10,1.5,.3) [1] 0.4783981