Mind the gap: Finding the text of C++ code called by an R function - c++

I would like to find the text of the C++ code called by an R function, specifically, the function "_dplyr_summarise_impl" which is called by summarise_impl. Even more specifically, I would like to find the bit of code that precedes that which returns the error message"
Error in summarise_impl(.data, dots) :
Evaluation error: argument "yes" is missing, with no default.
I presume that the "yes" in the code above varies, but that it is supplied by some other bit of dplyr or the related tidyverse, as none of my code possess a "yes" argument to be missing. Or it might be base R code called by tidyverse code. But in either case, there is a gap between the error message and the last function I could see with traceback, caused, I am guessing, by traceback being unable to find its way through called C++ code. I am hypothesizing that if I can find the code that was supposed to supply the "yes" argument, that will tell me what is going wrong. But there is a gap between the last function that traceback supplies and the error message above. I am looking for help in bridging that gap.
It now appears to me that this is a standard error message for some version of eval, either base or tidyverse, that is called either by _dplyr_summarise_impl, or some function that it calls. Many, perhaps all, of the dplyr major verbs have an unexported function of the form <function>_impl, and all of these functions return error messages very similar to the one previously cited. So I suspect they may be calling a common error message process.
I just found the text of _dplyr_summarise_impl here, in dplyr/src/RcppExports.cpp. That takes me one step closer, but I don't know enough C++ to know which of these lines is most likely to be calling the function that calls the error. Guess I'll read the C++ chapter in Advanced R next.
// summarise_impl
SEXP summarise_impl(DataFrame df, QuosureList dots);
RcppExport SEXP _dplyr_summarise_impl(SEXP dfSEXP, SEXP dotsSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< DataFrame >::type df(dfSEXP);
Rcpp::traits::input_parameter< QuosureList >::type dots(dotsSEXP);
rcpp_result_gen = Rcpp::wrap(summarise_impl(df, dots));
return rcpp_result_gen;
END_RCPP
}

Related

Using Lua from C++, Fails to open standard libs with Nil error

I've been writing Lua integration into a game project, and frustratingly, every time I try and use lua_pcall, I get the error "attempting to call nil value."
When I try to look up the error, most of the examples are of people who have forgotten to use pcall after loading their lua file, or some error down the line. But for me, it's as soon as I even attempt to load the lua standard libs. I don't understand what's going wrong with so little code to show for it. Other things I've tried are skipping openLibs and going straight to loading my file with doFile, but even in that case, anything I do at all will result in a nil error.
Any help is greatly appreciated.
EDIT:
Thanks to some help I determined that I didn't need to do a pcall for luaL_openlibs, but as I wrote above, trying to run any function at all results in errors. In this case, it can't find "init" in the global lua namespace
c++
void LuaScriptingInterface::init()
{
m_luaState = std::shared_ptr<lua_State>(luaL_newstate());
luaL_openlibs(m_luaState.get());
if (luaL_dostring(m_luaState.get(), m_script.c_str())) // script below
{
const char* errStr = lua_tostring(m_luaState.get(), -1);
ASSERT(false, errStr ); // not hitting this case
}
lua_getglobal(m_luaState.get(), "init");
if (!lua_isfunction(m_luaState.get(), -1))
{
ASSERT(false); // hit this case! Why can't we find "init"?
}
}
lua
init function ()
end
update function (dt)
end
It doesn't do anything yet of course, but I expect it should at least be able to find the function.
Hilariously the issue was in my FileReader code, there was an omitted newline character

RInside InternalFunction on a class, how to call the function from R

I need to call R from C++ and I am using the excellent RInside / Rccp packages.
I am not an R specialist, this might explain my question and sorry if it's too obvious.
I made an object and a wrapper class, something similar to the Rinside examples/standard/rinside_interactive0.cpp. In this example it shows how to attach a method to an R attribute class.
wr.attr("class") = "Solver";
R["Solver"] = wr;
... more code
R["names.Solver"] = Rcpp::InternalFunction(& Names); <-- Hot to call this one from R
Actually I never see a call from R to this function, and what would be the R syntax ? I though, using R.parseEval in such way:
R.parseEval("Solver.names()");
But this does not work and gives the error:
Error in Solver.names() : could not find function "Solver.names"
terminate called after throwing an instance of 'std::runtime_error'
what(): Error evaluating: Solver.names()
My question is then how to call the Solver.names function in R (that is handled in the C++ code) ?
Note that the assign / retrieval function are working fine, maybe because they are somehow "primitive" ?
Thanks a lot
Franck
I found out, I post in case someone is searching:
R.parseEval("names.Solver(Solver)");
Not very elegant to me .., it uses functionName.class(Object) ..
F.

Better errors with Ember

Is there a way to have clearer error messages when something is wrong with ember?
For exemple, I have this error 05:10:32,332 Error: Assertion Failed: A helper named 'eq' could not be found1 vendor.self-4fd4ab06f1f66c1cec72e1ec3a2c99328df792e46fb1fdcd0258c341b30a7c3b.js:24472:0
. This error is not the subject of the question, this is just an example.
I have no idea where is eq. The console indicated this function :
function EmberError() {
var tmp = Error.apply(this, arguments);
// Adds a `stack` property to the given error object that will yield the
// stack trace at the time captureStackTrace was called.
// When collecting the stack trace all frames above the topmost call
// to this function, including that call, will be left out of the
// stack trace.
// This is useful because we can hide Ember implementation details
// that are not very helpful for the user.
if (Error.captureStackTrace) {
Error.captureStackTrace(this, _emberMetalCore.default.Error);
}
// Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work.
for (var idx = 0; idx < errorProps.length; idx++) {
this[errorProps[idx]] = tmp[errorProps[idx]];
}
}
This is not related to my problem.
Obviouly, I searched eq in my code and I have no results. I suppose this is in a module but using grep is very ineffective.
Sometimes there is a stacktrace but its not very efficient too. To find an addon or the source in my code in a big vendor.js or myapp.js is not ideal.
Is there a better solution?
I think something in one of your addons or other third party code is using the ember-truth-helpers addon.
vendor.js typically contains third party code you've imported, not code that you've wrote.
As to the basic issue, it is really up to the maker of the third party code you've imported to document its dependencies and to ensure they are installed when you install that dependency. This really is not a failing of Ember itself, it has told you that there is no helper named eq and has given you the line number in the precompiled template where the eq was used. You can use the sources tab in Chrome to scroll to line 24472 in vendor.self-4fd4ab06f1f66c1cec72e1ec3a2c99328df792e46fb1fdcd0258c341b30a7c3b.js

Xerces: How to check the validity of an XML file using ErrorHandler

I am trying to determine if a given XML file is valid (has proper syntax and structure), and I am using Xerces. I have been able to succesfully read proper files but when I give it files with incorrect syntax, no errors are thrown.
I have been fishing around and found out that I might have to use an Error handler and user setErrorHandler to catch the errors instead of the traditional try-throw-catch exception handling.
The problem that I am having though is that I am very confused how to declare the proper handler, set it to my parser and then read the errors if there are any that show up.
Is there any chance somebody could shed some light on my situation?
// #input_parameter from function: const string & xmlConfigArg
xercesc::DOMDocument* doc = NULL;
string xmlConfig(xmlConfigArg);
Handler handler; // I'm not sure what type of handler to use
_parser->setErrorHandler(&handler);
try{
_parser->parse(xmlConfigArg.c_str());
doc = _parser-> getDocument();
}catch(...){
//Nothing is ever caught here
}
You need to derive a class from ErrorHandler (< xercesc/sax/ErrorHandler.hpp >)
then overwrite all the virtual methods there.
After doing so, You can get the error code from the class you created. No exceptions will be thrown in the parsing, so you can wave the try/cache block (or keep it for a different use).

Error while calling member function

Hi I have just started using C++ today, and I am working on checkboxes. I have tried using CheckBox1->Checked in an if statement or whatever, but it isn't working.
The error is:
Error 2 error C2227: left of '->Checked' must point to class/struct/union/generic type
EDIT: The Code is:
void function ()
{
if (1001->Checked)
{
Sleep(2000);
}
}
Without seeing some of your code, it's very difficult to offer targeted assistance.
However, that error message usually comes about because the item you're de-referencing is not a pointer.
Check to ensure it's of the correct type. It should be something along the lines of:
tCheckBox *CheckBox1;
One possibility is that you've declared it not as a pointer to the checkbox but as a checkbox itself:
tCheckBox CheckBox1;
Note the lack of the asterisk there that would otherwise mark it as a pointer. In that case, you would use CheckBox1.Checked rather than CheckBox1->Checked, if it's allowed by the framework (this isn't standard C++ since that beast has no concept of GUI libraries).
If that doesn't help, please post the code so we can offer better suggestions.
Update:
if (1001->Checked) ?????
1001 is not a pointer - it's not a variable of any description, it's an integer constant.
You need to declare and use a variable of some description. First step is, I think, to read up on the documentation for your framework and/or get some sample code that does compile and work, basing your initial work of that.
Use CButton::GetCheck() to determine the state of the checkbox - like so...
CButton* pButton = (CButton*) GetDlgItem(IDC_CHECKBOX_RESOURCE_ID);
if ( BST_CHECKED == pButton->GetCheck() )
{
// button is checked
}