inline std::string getFunctionHeaderShort()

in src/RStuff/RUtil.h [182:204]


inline std::string getFunctionHeaderShort(SEXP func) {
  SHIELD(func);
  if (TYPEOF(func) == BUILTINSXP || TYPEOF(func) == SPECIALSXP) {
    return getFunctionHeader(func);
  }
  if (TYPEOF(func) != CLOSXP) return "";
  SEXP args = FORMALS(func);
  std::string s = "function(";
  ShieldSEXP names = Rf_getAttrib(args, R_NamesSymbol);
  int i = 0;
  while (TYPEOF(args) == LISTSXP) {
    if (i > 0) s += ", ";
    const char* name = TYPEOF(names) == STRSXP && Rf_xlength(names) > i ? asStringUTF8(STRING_ELT(names, i)) : ".";
    s += quoteIfNeeded(name);
    if (TYPEOF(CAR(args)) != SYMSXP || strlen(CHAR(PRINTNAME(CAR(args)))) > 0) {
      s += " = NULL";
    }
    args = CDR(args);
    ++i;
  }
  s += ")";
  return s;
}