How can I call a .C function compiled with Matlab Coder in R?

2 visualizzazioni (ultimi 30 giorni)
I would like to call a C function compiled using Matlab Coder in R for later use in a Shiny app. How can I go about doing this. The top of the .C function looks like this:
double ensembleBaggedTreesExtendedStay_V1(double TransferredYesNo,
double BleedDisYesNo,
double PreOpAlbumin, double PreOpHCT,
double ASAClass, double ComplexYesNo)
and the file name for the c function is "ensembleBaggedTreesExtendedStay_V1.c"
I have very limited knowledge of R and .C and I would appreciate any help.

Risposte (1)

Harsh
Harsh il 2 Gen 2025
Hi Arsalan,
Proceed with the steps outlined below to call the C function generated by MATLAB coder in R using .C( )
  • Modify your ensembleBaggedTreesExtendedStay_V1 function such that it returns void and stores the desired result in one or more arguments expressly created for this purpose. Also, the function should have a C_ prefix.
  • Compile the function into a shared library accessible to R using this command:
R CMD SHLIB ensembleBaggedTreesExtendedStay_V1.c
  • Within an active R session, link to the shared library using dyn.load("ensembleBaggedTreesExtendedStay_V1.so").
  • Write an R wrapper to call the C function using .C with the following syntax: .C("C_my_func", arg1, arg2).
Hope this resolves your query. Happy coding !

Categorie

Scopri di più su MATLAB Coder in Help Center e File Exchange

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by