The R Project SVN R

Rev

Rev 15947 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 15947 Rev 16302
Line 724... Line 724...
724
  R_stdGen_ptr_t old = R_standardGeneric_ptr;
724
  R_stdGen_ptr_t old = R_standardGeneric_ptr;
725
  R_standardGeneric_ptr = val;
725
  R_standardGeneric_ptr = val;
726
  return old;
726
  return old;
727
}
727
}
728
 
728
 
-
 
729
static void load_methods_package()
-
 
730
{
-
 
731
  SEXP e;
-
 
732
  PROTECT(e = allocVector(LANGSXP, 2));
-
 
733
  SETCAR(e, install("library"));
-
 
734
  SETCAR(CDR(e), install("methods"));
-
 
735
  eval(e, R_NilValue);
-
 
736
  UNPROTECT(1);
-
 
737
}
-
 
738
 
729
SEXP do_standardGeneric(SEXP call, SEXP op, SEXP args, SEXP env)
739
SEXP do_standardGeneric(SEXP call, SEXP op, SEXP args, SEXP env)
730
{
740
{
731
  SEXP arg, value; R_stdGen_ptr_t ptr = R_get_standardGeneric_ptr();
741
  SEXP arg, value; R_stdGen_ptr_t ptr = R_get_standardGeneric_ptr();
732
  if(!ptr)
742
  if(!ptr) {
733
    error("Using standardGeneric before the methods package has been attached");
743
    warning("standardGeneric called before the methods package has been attached (library(methods) will be evaluated now)");
-
 
744
    load_methods_package();
-
 
745
    ptr = R_get_standardGeneric_ptr();
-
 
746
    if(!ptr)
-
 
747
      error("Something went wrong:  the internal pointer for standardGeneric was not set");
734
 
748
  }
735
  checkArity(op, args);
749
  checkArity(op, args);
736
 
750
 
737
  PROTECT(arg = CAR(args));
751
  PROTECT(arg = CAR(args));
738
 
752
 
739
  value = (*ptr)(arg, env);
753
  value = (*ptr)(arg, env);