Libraries: mt-R - page 3

 
cgarbelli:

Hello,


I'm trying to use the RAssignStringVector function, but it seems that only the first char of each term is copied to R session.

For example the MQL5 vector

{"abcd","2000","2000}

is copied to R as

{"a","2","2"}

It's an issue or I'm wrong?

Note that I'm using RAssignVector with double vector without problems.


Thanks.

Claudio.

I do not use MT5, sorry

 

Attention!
In the R.mqh file the names of variables vector and matrix started to generate an error during compilation. Rename them to other ones and everything will work. I used vectr and matr.

The editor highlights these words in blue as a data type like int, double. Apparently they reserved words for new types.

 

Description of all functions (copied from previous version https://www.mql5.com/en/code/11112)

/**
* Return the dll version. The upper 16 bits of the return value
* are the major version and the lower 16 bits the minor. This
* is used in RInit() to make sure that this header file and
* zzthe dll fit together.
*/
int RGetDllVersion();

/**
* This is not meant to be called directly, it will be
* called by RInit() after the successful version check.
* You should call RInit() to start a new R session.
*/
long RInit_(string commandline,int debuglevel);

/**
* Teminate the R session. Call this in your deinit() function.
* After this the handle is no longer valid.
*/
void RDeinit(long rhandle);

/**
* return true if the R session belonging to this handle is
* still running. R will terminate on any fatal error in the
* code you send it. You should check this at the beginning
* of your start function and stop all actions. The last
* command prior to the crash will be found in the log.
* If R is not running anymore this library won't emit any
* more log messages and will silently ignore all commands.
*/
bool RIsRunning(long rhandle);

/**
* return true if R is still executing a command (resulting
* from a call to RExecuteAsync())
*/
bool RIsBusy(long rhandle);

/**
* execute code and do not wait. Any subsequent call however
* will wait since there can only be one thread executing at
* any given time. Use RIsBusy() to check whether it is finished
*/
void RExecuteAsync(long rhandle,string code);

/**
* execute code and wait until it is finished. This will not
* return anything. You can basically achieve the same with
* the RGet*() functions, evaluating the expression is also
* just executig code, the only difference is that these
* RGet*() functions will additionally try to parse and return
* the output while RExecute() will just execute, wait and
* ignore all output.
*/
void RExecute(long rhandle,string code);

/**
* assign a bool to the variable name. In R this type is called "logical"
*/
void RAssignBool(long rhandle,string variable,bool value);

/**
* assign an integer to the variable name.
*/
void RAssignInteger(long rhandle,string variable,int value);

/**
* assign a double to the variable name.
*/
void RAssignDouble(long rhandle,string variable,double value);

/**
* assign a string to the variable namd. In R this type is called "character"
*/
void RAssignString(long rhandle,string variable,string value);

/**
* assign a vector to the variable name. If the size does not match
* your actual array size then bad things might happen.
*/
void RAssignVector(long rhandle,string variable,double &vectr[],int size);

/**
* assign a vector of character (an array of strings) to the variable. If you need
* a factor then you should execute code to convert it after this command. In
* recent versions of R a vector of strings does not need any more memory than
* a factor and it is easier to append new elements to it.
*/
void RAssignStringVector(long rhandle,string variable,string &vectr[],int size);

/**
* assign a matrix to the variable name. The matrix must have the row number as the
* first dimension (byrow=TRUE will be used on the raw data). This function is much
* faster than building a huge matrix (hundreds of rows) from scratch by appending
* new rows at the end with RRowBindVector() for every row. This function is optimized
* for huge throughput with a single function call through using file-IO with the
* raw binary data. For very small matrices and vectors with only a handful of elements
* this might be too much overhead and the other functions will be faster. Once you
* have the matrix with possibly thousands of rows transferred to R you should then
* only use RRowBindVector() to further grow it slowly on the arrival of single new
* data vectors instead of always sending a new copy of the entire matrix.
*/
void RAssignMatrix(long rhandle,string variable,double &matr[],int rows,int cols);

/**
* append a row to a matrix or dataframe. This will exexute
* variable <- rbind(variable, vector)
* if the size does not match the actual array size bad things might happen.
*/
void RAppendMatrixRow(long rhandle,string variable,double &vectr[],int size);

/**
* return true if the variable exists, false otherwise.
*/
bool RExists(long rhandle,string variable);

/**
* evaluate expression and return a bool. Expression can be any R code
* that will evaluate to logical. If it is a vector of logical then only
* the first element is returned.
*/
bool RGetBool(long rhandle,string expression);

/**
* evaluate expression and return an integer. Expression can be any R code
* that will evaluate to an integer. If it is a floating point it will be
* rounded, if it is a vector then only the first element will be returned.
*/
int RGetInteger(long rhandle,string expression);

/**
* evaluate expression and return a double. Expression can be any R code
* that will evaluate to a floating point number, if it is a vector then
* only the first element is returned.
*/
double RGetDouble(long rhandle,string expression);

/**
* evaluate expression and return a vector of doubles. Expression can
* be anything that evaluates to a vector of floating point numbers.
* Return value is the number of elements that could be copied into the
* array. It will never be bigger than size but might be smaller.
* warnings are output on debuglevel 1 if the sizes don't match.
* >>> Limited to 100000 elements
*/
int RGetVector(long rhandle,string expression,double &vectr[],int size);

/**
* do a print(expression) for debugging purposes. The outout will be
* sent to the debug monitor on debuglevel 0.
*/
void RPrint(long rhandle,string expression);

mt4R for new MQL4
mt4R for new MQL4
  • www.mql5.com
mt4R, modified for supporting new MQL4
 
Great job!

Could you help to solve problem which appears in specific situation.

1) run two mt5 terminals of two different brokers  
2) copy everything between each other
3) run experts with using your dll and sending arrays from mt5 to Rterm
4) wait for a some minutes
 One of two mt5 terminals will be closed.
 
Why and how to fix it?

Thanks.