The reason the R bridge on supports a very limited set of return types is because it is a wrapper around the mt4 R interface, which only supports int, double and double vector types.

Indexing the symbols, and then sharing this information between R and C seems like an unpleasant kluge. Also, I might need string vectors from R for other purposes.

So I wrote my own "extension" of the R bridge that supports this. I used quotes because it involves "cheating" by passing values back from R using a JSON file.

Here is the example script demonstrating, in case anyone is interested:


#include <r.h>
#include <Rcom.c>

function main()
{
if(!Rstart()) {
printf("Error - R won't start!");
return;
}

// Initialize Rcom
Rcom_init();

// Example: Rstrings
// Get a vector of strings of unknown length:
// Listing of ZorroFolder
char* expression = strf("dir('%s')", slash(ZorroFolder));
char** zorro_dir;
int max_strings = 10000;
int num_files = Rstrings(expression, &zorro_dir, max_strings);
printf("n%d files:", num_files);
int i;
for (i = 0; i < num_files; ++i)
printf("n%s", zorro_dir[i]);

// Example: Rsv
// Get a vector of strings of known length:
// Column names of mtcars
Rx("data(mtcars)");
int ncols = Rd("ncol(mtcars)");
char** col_names = malloc(ncols * sizeof(char*));
Rsv("colnames(mtcars)", col_names, ncols);
printf("nnmtcars has %d columns:", ncols);
for (i= 0; i < ncols; ++i) {
printf("n%s", col_names[i]);
}

// Example: Rs2
// Get a single string:
// digest of mtcars
// Note that Rs is already defined in r.h for debugging purposes.
Rx("{ install.packages('digest', repos = 'https://cloud.r-project.org'); library(digest) }");
char* digest = Rs2("digest(mtcars)");
printf("nndigest of mtcars: %s", digest);

return;
}