MCPcopy Create free account
hub / github.com/RcppCore/Rcpp / cppNumericArgToRArg

Function cppNumericArgToRArg

src/attributes.cpp:2610–2638  ·  view source on GitHub ↗

convert a C++ numeric argument to an R argument value (returns empty string if no conversion is possible)

Source from the content-addressed store, hash-verified

2608 // convert a C++ numeric argument to an R argument value
2609 // (returns empty string if no conversion is possible)
2610 std::string cppNumericArgToRArg(const std::string& type,
2611 const std::string& cppArg) {
2612 // check for a number
2613 double num;
2614 std::stringstream argStream(cppArg);
2615 if ((argStream >> num)) {
2616
2617 // L suffix means return the value literally
2618 if (!argStream.eof()) {
2619 std::string suffix;
2620 argStream >> suffix;
2621 if (argStream.eof() && suffix == "L")
2622 return cppArg;
2623 }
2624
2625 // no decimal and the type isn't explicitly double or
2626 // float means integer
2627 if (cppArg.find('.') == std::string::npos &&
2628 type != "double" && type != "float")
2629 return cppArg + "L";
2630
2631 // otherwise return arg literally
2632 else
2633 return cppArg;
2634 }
2635 else {
2636 return std::string();
2637 }
2638 }
2639
2640 // convert a C++ ::create style argument value to an R argument
2641 // value (returns empty string if no conversion is possible)

Callers 1

cppArgToRArgFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected