Can't get RCaller to work, get error on line caller.runAndReturnResult - rcaller

I am trying to use Rcaller with simple example code as follows
public class rcaller {
public static void main(String[] args) {
RCaller caller = RCaller.create();
RCode code = RCode.create();
double[] arr = new double[] { 1.0, 2.0, 3.0 };
code.addDoubleArray("myarr", arr);
code.addRCode("avg <- mean(myarr)");
caller.setRCode(code);
caller.runAndReturnResult("avg");
double[] result = caller.getParser().getAsDoubleArray("avg");
System.out.println(result[0]);
}
}
I am getting the following error on the line runAndReturnResult:
Exception in thread "main" java.lang.IllegalArgumentException: Illegal character in opaque part at index 2: C:\Users\uceesro\AppData\Local\Temp\ROutput11009463111314803062
at java.base/java.net.URI.create(URI.java:906)
at com.github.rcaller.rstuff.RCode.appendStandardCodeToAppend(RCode.java:109)
at com.github.rcaller.rstuff.RCaller.runAndReturnResult(RCaller.java:576)
at rcaller.rcaller.main(rcaller.java:21)
Caused by: java.net.URISyntaxException: Illegal character in opaque part at index 2: C:\Users\uceesro\AppData\Local\Temp\ROutput11009463111314803062
at java.base/java.net.URI$Parser.fail(URI.java:2938)
at java.base/java.net.URI$Parser.checkChars(URI.java:3109)
at java.base/java.net.URI$Parser.parse(URI.java:3145)
at java.base/java.net.URI.<init>(URI.java:623)
I have tried using different versions of R but get the same issue. Any help would be appreciated.

"Found issue seems to be a problem with rcaller 4.0.0" — yes, this problem really exists on Windows (and had not been found during the development and CI tests). Please try 4.0.1

Found issue seems to be a problem with rcaller 4.0.0 with 3.0 it works fine

Related

C++ Code Smell: Incorrect Initializer Braces Placement

I am trying to fix the following code smell within my C++ code generated from Klocwork(KW):
MISRA.INIT.BRACES: Incorrect initializer braces placement
Below is a snippet of the code I am attempting to clean this up on.
typedef char charString[10];
enum SomeEnum
{
BLAH1_e,
BLAH2_e,
BLAH3_e
};
struct ParentStruct
{
SomeEnum myEnumValue;
charString myCharStringValue;
};
// This is the the part that KW is not happy about
// KW complaining about initializer bracer placement
const ParentStruct myParent[3] =
{
{BLAH1_e, "String1"},
{BLAH2_e, "String2"},
{BLAH3_e, "String3"}
}
I've attempted many variations of bracer placement and can't seem to figure out the exact issue with bracer placement I currently have. This doesn't generate any compile errors nor does this have a negative outcome on the code. Maybe it's just KW but just wanted to get some thoughts before I give up completely.
Below is an alternative bracer placement I attempted as well in case someone throws it out as an answer:
// compiles but KW does not like this as well
const ParentStruct myParent[3] =
{
{BLAH1_e, {"String1"}},
{BLAH2_e, {"String2"}},
{BLAH3_e, {"String3"}}
}
Please do run the analysis with the latest version of Klocwork and check if this issue has been reported by Klocwork at your end.
I am using Klocwork 2021.3 and it seems that MISRA.INIT.BRACES checker is not reporting any issue on your code as expected.

How to get an explanatory string from std::regex_error?

My program is throwing an std::regex_error(). I'd like to know what the error is, since the regex looks legit to me. I did essentially this:
try {
// offending code
} catch (std::regex_error& e) {
log_error("Regex error: " << e.what() << ", " << e.code());
}
The output is:
Regex error: regex_error, 4
This isn't particularly helpful. What does 4 mean? The en.cppreference.com entry for code() only says:
Returns the std::regex_constants::error_type that was passed to the std::regex_error constructor.
The entry for error_type gives a list of error codes, all of whose exact values are "unspecified".
Do I have no recourse but to do something like this?
switch (e.code()) {
case std::regex_constants::error_collate: return "error_collate";
case std::regex_constants::error_ctype: return "error_ctype";
// etc ...
}
This is a quality-of-implementation issue in the standard C++ library, which is a nice way of saying that it's a bug. GCC bug 67361, to be exact ("std::regex_error::what() should say something about the error_code").
There is a recently submitted patch in the bug report, so I suppose that it will eventually show up as an upgrade. [Update: According to the bug report above, it was fixed in v6.1 (released April 26, 2016) but the bug report was not marked as resolved until November 19, 2018. Anyway, if you have a reasonably recent distribution, this should not be a problem any more.]
In the meantime, you have little option but to roll your own code->message conversion function. (Or, as an interim debugging method, consult include/bits/regex_error.h)
An alternative to using the switch is to define your own enum for each regex error code and cast the result to that, giving you better runtime debugging aid.
enum class RegexError {
collate = std::regex_constants::error_collate,
ctype = std::regex_constants::error_ctype,
// etc
};
RegexError errorCode = static_cast<RegexError>( e.code() );
// your debugger will now show you what the meaning of errorCode is
That way you don't need to use strings.
However, if you want to display the error to the user in a human-readable fashion then you will need to use strings, but you can use a map to store them:
map<RegexError, wchar_t const * const> errorMessages;
errorMessages[RegexError::collate] = L"the expression contains an invalid collating element name";
errorMessages[RegexError::ctype ] = L"the expression contains an invalid character class name";
// etc

QScriptEngine: bad expression considered valid

I need to implement a simple math expression calculator like 1+2*(3.4 + 0.1)
I thought it'd be quite easy to implement the stuff using
QScriptEngine::evaluate()
but there is a problem: some invalid expressions is considered valid and evaluated to something instead of producing an error.
Example:
QString expression = "1 + 2*("; // <---- wrong expression
auto checkResult = QScriptEngine::checkSyntax(expression);
if (checkResult.state() == QScriptSyntaxCheckResult::Valid)
{
QScriptEngine engine;
auto scriptResult = engine.evaluate(expression);
if (scriptResult.isValid() && scriptResult.isNumber())
{
double value = scriptResult.toNumber(); // <---- the value is 3.0, instead of an error
}
}
So my question is: am I missing something and there is a way I can check the syntax of an expression before a QScriptEngine::evaluate() using Qt?
Another way is to use Lepton library (or similiar one), but I'd prefer to not include other 3rd party components.
Unfortunately there was a configuration/Qt issue. Updating to the latest Qt5.5 & rebuilding the project solved the problem. Thank you #hyde.

" malloc error pointer being freed was not allocated " error only in simulator:

When I debug on actual devices, there is no error, but when I use the simulator, Xcode's debugger console displays the following error when running:
malloc: *** error for object 0xaaaaaaaa: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
The error always happens at the same line, which is in the constructor of another class:
Segment *segment = new Segment(0.0,0.0,3.0,1.3,10);
this->segments.push_back(segment); // Malloc error at this line
My Segment class:
class Segment {
private:
float ajc;
float frl;
std::unordered_map<int,int> jgrc;
std::vector<int> lorb;
public:
std::tuple<float,float> getMjt();
float getBuw();
….
Segment(float a, float f,float g, float lo, float u){
……
};
};
On the simulator, regardless of iOS version, the error appears. On devices, regardless of version, there is no error.
I have heard about the rule of 3, but in this case I don't think I need to apply it because the default compiler supplied code should work (unless I'm mistaken). What am I doing wrong, and how can I fix this ? Since there is no error reported on devices, should i ignore it ?
First put a NULL check to avoid the run time error. I tried a pseudo code on VS and it seemed to work. I hope your vector is similar.
Segment *segment = new Segment(0.0, 0.0, 3.0, 1.3, 10);
std::vector<Segment*> vec;
if (NULL != segment)
vec.push_back(segment);
I think there is some problem with your simulator not working fine.
The solution works, but I don't understand why. If someone with more c++ can explain it well, I will mark that as the correct answer.
The following code runs in the constructor of my class that creates the segments:
Segment *segment = new Segment(0.0,0.0,3.0,1.3,10);
this->segments.push_back(segment); // Malloc error at this line
First, I used objects instead of the pointer. Then I moved the code out of the constructor, and instead call it immediately after creating an instance of the class.
Say my class is:
class MyClass{
std::vector<Segment> segments;
}
I do :
MyClass *foo = new MyClass();
foo->createSegments();
Where:
createSegments(){
Segment segment = Segment(0.0,0.0,3.0,1.3,10);
segments.push_back(segment);
}
I'm not very experienced with C++, so I don't know why this works.I also still don't know why the original error only appeared in the simulator.

Problems after upgrading IBM C++ compiler from xlc_R 10.0 to 11.1

Everything compiles fine, but during run time, it crashes without any coredumps, exceptions or no logs clues about what is happening. After inserting debug lines, I found that it was around this section of code
if( MISC_TABLE_ID != tableID )
{
OrbSchemaStructure orbSchemaStruct;
orbSchemaStruct.tableName = tableView;
orbSchemaStruct.columnName = colName;
orbSchemaStruct.dataType = tsFact->convertDBDataTypeToEVDataType( toString( col.type() ) );
orbSchemaStruct.primaryKeyComponent = pkComponent;
schemaStructureDeque.push_back( orbSchemaStruct ); //crashes after this line
}
And it is happening on the last line of this block, where the push_back happens.
and the schemaStructureDeque happens to be an object of type DEQUE< OrbSchemaStructure >& schemaStructureDeque where DEQUE is a define for std::deque.
The OrbSchemaStructure is a struct defined in an idl as follows :
struct OrbSchemaStructure
{
string tableName;
string columnName;
unsigned long dataType;
boolean primaryKeyComponent;
};
Was there any change to the way deques are handled? Am I missing something?
Before writing this question off as too localized, please let me know if I am missing any info, or if I am not looking in the right place.
I am using omniORB 4.0.4 btw.
On compiling in the omniORB on AIX using the new AIX 11.1 C++ compiler, and linking it with the binary, it has stopped crashing.