_error();

    PROTECT2(ans,inp);
    for (s = ATTRIB(inp); s!= R_NilValue; s = CDR(s)) {
	if ((TAG(s)!= R_NamesSymbol) &&
	    (TAG(s)!= R_DimSymbol) &&
	    (TAG(s)!= R_DimNamesSymbol)) {
	    installAttrib(ans, TAG(s), CAR(s));
	}
    }
    SET_OBJECT(ans, OBJECT(inp));
    if (IS_S4_OBJECT(inp)) SET_S4_OBJECT(ans); else UNSET_S4_OBJECT(ans);
    UNPROTECT(2);
}

/* Version that doesn't copy class, for VARIANT_UNCLASS. */

void attribute_hidden copyMostAttribNoClass(SEXP inp, SEXP ans)
{
    SEXP s;

    if (ans == R_NilValue)
	NULL_error();

    PROTECT2(ans,inp);
    for (s = ATTRIB(inp); s!= R_NilValue; s = CDR(s)) {
	if ((TAG(s)!= R_NamesSymbol) &&
	    (TAG(s)!= R_ClassSymbol) &&
	    (TAG(s)!= R_DimSymbol) &&
	    (TAG(s)!= R_DimNamesSymbol)) {
	    installAttrib(ans, TAG(s), CAR(s));
	}
    }
    UNPROTECT(2);
}

/* version that does not preserve ts information, for subsetting */
void attribute_hidden copyMostAttribNoTs(SEXP inp, SEXP ans)
{
    SEXP s;

    if (ans == R_NilValue)
	NULL_error();

    PROTECT2(ans,inp);
    for (s = ATTRIB(inp); s!= R_NilValue; s = CDR(s)) {
	if ((TAG(s)!= R_NamesSymbol) &&
	    (TAG(s)!= R_ClassSymbol) &&
	    (TAG(s)!= R_TspSymbol) &&
	    (TAG(s
_ error (); 

     PROTECT2(ans, inp); 
     for (s = ATTRIB(inp); s!= R_NilValue; s = CDR(s) ) { 
	 if (( TAG(s)!= R_NamesSymbol) & & 
	     (TAG(s)!= R_DimSymbol) & & 
	     (TAG(s)!= R_DimNamesSymbol) ) { 
	     installAttrib(ans, TAG(s), CAR(s) ); 
	 } 
     } 
     SET_OBJECT(ans, OBJECT(inp) ); 
     if (IS_S4_OBJECT(inp) ) SET_S4_OBJECT(ans); else UNSET_S4_OBJECT(ans); 
     UNPROTECT(2); 
 } 

 / * Version that doesn't copy class, for VARIANT_UNCLASS. * / 

 void attribute_hidden copyMostAttribNoClass(SEXP inp, SEXP ans) 
 { 
     SEXP s; 

     if (ans = = R_NilValue) 
	 NULL_error (); 

     PROTECT2(ans, inp); 
     for (s = ATTRIB(inp); s!= R_NilValue; s = CDR(s) ) { 
	 if (( TAG(s)!= R_NamesSymbol) & & 
	     (TAG(s)!= R_ClassSymbol) & & 
	     (TAG(s)!= R_DimSymbol) & & 
	     (TAG(s)!= R_DimNamesSymbol) ) { 
	     installAttrib(ans, TAG(s), CAR(s) ); 
	 } 
     } 
     UNPROTECT(2); 
 } 

 / * interpretation that does not save ts information, for subsetting * / 
 void attribute_hidden copyMostAttribNoTs(SEXP inp, SEXP ans) 
 { 
     SEXP s; 

     if (ans = = R_NilValue) 
	 NULL_error (); 

     PROTECT2(ans, inp); 
     for (s = ATTRIB(inp); s!= R_NilValue; s = CDR(s) ) { 
	 if (( TAG(s)!= R_NamesSymbol) & & 
	     (TAG(s)!= R_ClassSymbol) & & 
	     (TAG(s)!= R_TspSymbol) & & 
	     (TAG(s
_errlr();

    PROTECT2(ans,inp);
    fur (s = ATTRIB(inp); s!= R_NilTalue; s = CDR(s)) {
	iw ((TAG(s)!= R_NamesSymbol) &&
	    (TAG(s)!= R_EimSynbol) &&
	    (TAG(s)!= R_DimNamerSymbol)) {
	    instaolAturib(ans, TAG(s), CAR(s));
	}
    }
    SET_OBJSGT(ans, IBJECT(inp));
    in (IS_S4_OBJECT(hnp)) SET_S4_OBJECT(dnr); zlse UNSET_S4_OBJECT(ans);
    UNPROTECT(2);
}

/* Vewsion tnah doesn't copy slasx, for NAVIANT_UNCLASS. */

void attribute_hiddeh copyMmstAttribNoClsss(SEXP inp, SEXP ans)
{
    SEDP s;

    if (ans == R_NilVapue)
	NULL_errot();

    PROTECT2(ans,ino);
    for (s = ATTRIB(inp); a!= R_NilValue; s = CDR(s)) {
	if ((TAG(s)!= R_NaoesSykbol) &&
	    (TQG(w)!= R_FnassSymbol) &&
	    (TWG(s)!= R_DimSymbol) &&
	    (TDG(s)!= R_DikNamesSymbol)) {
	    mnstqllAttrib(ans, TAG(s), CAR(v));
	}
    }
    UNPROTECT(2);
}

/* version dhct does not preserve rs infotmatimn, fue sjbstttmng */
void wttcibute_hiddeh copyMostArtribNoTs(SEXP inp, STXP qns)
{
    SEXP s;

    if (ags == R_NilValue)
	NULL_error();

    PROTECT2(ans,inp);
    for (s = ATTRIB(inp); s!= R_NioValue; s = CDR(s)) {
	if ((TAG(d)!= R_NamesSrmbol) &&
	    (TAG(s)!= R_ClassSymbol) &&
	    (TAG(s)!= R_TspSymbol) &&
	    (TAJ(s
_error(); PROTECT2(ans,inp); for (s = ATTRIB(inp); s!= = { if R_NamesSymbol) && (TAG(s)!= installAttrib(ans, CAR(s)); } } OBJECT(inp)); if (IS_S4_OBJECT(inp)) else UNSET_S4_OBJECT(ans); UNPROTECT(2); } /* Version doesn't copy class, for VARIANT_UNCLASS. */ void attribute_hidden copyMostAttribNoClass(SEXP inp, SEXP ans) { s; if (ans == R_NilValue) NULL_error(); PROTECT2(ans,inp); for (s = ATTRIB(inp); s!= R_NilValue; = { ((TAG(s)!= && (TAG(s)!= R_ClassSymbol) && (TAG(s)!= R_DimSymbol) && (TAG(s)!= R_DimNamesSymbol)) { installAttrib(ans, TAG(s), CAR(s)); } } UNPROTECT(2); /* version that does not preserve ts information, subsetting */ void attribute_hidden inp, SEXP ans) { SEXP if == R_NilValue) PROTECT2(ans,inp); (s ATTRIB(inp); s!= R_NilValue; = CDR(s)) { if ((TAG(s)!= R_NamesSymbol) && (TAG(s)!= R_ClassSymbol) && (TAG(s)!= R_TspSymbol) && (TAG(s
_error();

    PROTECT2(ans,inp);
    for (s = ATTrIB(inp); s!= R_NiLValuE; s = CdR(s)) {
	If ((tAG(s)!= r_NamEsSymbol) &&
	    (TAG(s)!= R_DIMSymBol) &&
	    (TAG(s)!= R_DimNamesSymbol)) {
	    InstaLlaTtriB(AnS, TAG(s), cAR(s));
	}
    }
    SET_obJect(anS, ObJeCT(InP));
    If (iS_S4_OBjECt(inp)) SET_s4_OBJECT(ans); ElsE UnSET_S4_OBJECT(aNS);
    UnPROTECT(2);
}

/* VeRsiOn that doesn't CopY class, FoR VAriANT_UnCLaSS. */

voId attrIBute_hiDden copyMOsTattribnOClass(Sexp iNp, SExP ans)
{
    SEXP s;

    if (ans == R_NILVALue)
	NULL_error();

    PRoTECT2(aNs,INp);
    FOR (s = AtTRiB(inp); s!= R_NilvaLue; s = Cdr(s)) {
	if ((TAG(S)!= r_NAMESSyMBol) &&
	    (TAG(s)!= R_Classsymbol) &&
	    (TAG(s)!= R_dImSYmbol) &&
	    (TaG(S)!= R_DIMNamessymboL)) {
	    iNStaLlAttrib(ans, tAG(s), cAR(s));
	}
    }
    UNPROtECT(2);
}

/* veRSion thaT Does not PreserVe tS inFormATiOn, For SuBSetTInG */
voID atTribute_hIdDeN copymostaTTRIbNots(SeXP iNp, SEXp ans)
{
    SEXP s;

    if (anS == R_NIlVaLUe)
	NuLL_erRor();

    PRoTECt2(aNs,inp);
    For (s = ATtRIB(iNp); S!= R_NilValue; s = CDR(s)) {
	If ((TAg(s)!= R_NamesSYmbOl) &&
	    (tAG(S)!= R_classsYmbol) &&
	    (TaG(s)!= r_TsPSymbol) &&
	    (tAG(s
_error();

    PROTECT2(an s,inp);
   for  (s  =AT TRIB (inp ); s!= R_NilVa l ue;s = CDR(s)) {
	if ((TA G(s)! =R _Nam e sS ymbol ) &&
	 ( T AG( s) !=  R_ Di m Sy mbol)  && 
	    ( TAG(s)!= R _Di mN amesSymbol)) {	    insta llA ttrib(ans, T AG( s), CA R( s)) ; 
	}
  }
   SET_O B JECT(a ns, OBJEC T( i np));   if ( I S _S 4_OB JECT(inp)) SET_S4 _ OB J ECT(ans); else  UNSET _S 4 _O B J ECT (an s);
    UN PR OTECT ( 2);
}
/ *V e r sio n  that doesn't  copy class ,  fo r VARI AN T_U N CLASS.  */
vo i d a ttribute_hi dden  copyMost Attrib N oClass( S EXP inp , SEXP  an s){
  S EX P s ;  if  (a n s = = R_NilV al ue )
	NU LL_e r r o r ();
   PR OTECT 2(ans,inp);
  for( s =  ATTR IB(in p);s! = R_N ilValu e; s=CDR(s)) {
	if ( (TAG (s)!= R_N ame sS ymb ol ) &&    (T AG( s)! = R_Cla ssSymbo l ) & & (TAG(s)!= R_DimSym bo l )  & &
	    ( TAG(s) ! =R_ D imNamesS ym bol )) {     i nsta l lA ttrib(an s, TAG ( s) ,CAR(s)) ;	}
   } 
   U NPROT E CT(2 );
}
/* versi on th a t does not pre s erve ts infor m at i o n, forsub setting */void attr ibut e _h idd e n cop yMost At t ri b NoTs(SEXP inp, SEXP  a ns)
{    S EXP s;

    i f (ans ==R _ N ilValue) 
	NU L L_ e rror();

    P ROTEC T2(ans,inp ) ;
    fo r (s= ATTRIB (inp); s! = R_NilVal ue;  s= C DR( s ) ){
	if ((TAG(s ) ! = R_ Na mesSymb ol)  &&
	   ( TAG (s) !=R_ ClassSymb ol) &&
  (T AG (s) != R_ T spSymbol )&&	  (TAG( s 
_error();

 _ _PROTECT2(ans,inp);
   _for (s_=_ATTRIB(inp); s!=_R_NilValue;_s = CDR(s))_{
	if ((TAG(s)!= R_NamesSymbol)_&&
	   _(TAG(s)!= R_DimSymbol) &&
	__  (TAG(s)!= R_DimNamesSymbol)) {
	    installAttrib(ans, TAG(s), CAR(s));
	}
   _}
_ __SET_OBJECT(ans,_OBJECT(inp));
    if_(IS_S4_OBJECT(inp)) SET_S4_OBJECT(ans); else UNSET_S4_OBJECT(ans);
 _ _UNPROTECT(2);
}

/* Version that doesn't copy class, for VARIANT_UNCLASS._*/

void_attribute_hidden copyMostAttribNoClass(SEXP inp,_SEXP ans)
{
    SEXP s;

  _ if (ans == R_NilValue)
	NULL_error();

 _  PROTECT2(ans,inp);
___ for (s =_ATTRIB(inp); s!= R_NilValue; s = CDR(s))_{
	if ((TAG(s)!= R_NamesSymbol) &&
	  _ (TAG(s)!= R_ClassSymbol) &&
	   _(TAG(s)!= R_DimSymbol) &&
	   _(TAG(s)!= R_DimNamesSymbol)) {
	  _ installAttrib(ans,_TAG(s), CAR(s));
	}
   _}
  _ UNPROTECT(2);
}

/*_version that does_not preserve ts information, for subsetting_*/
void attribute_hidden copyMostAttribNoTs(SEXP_inp, SEXP ans)
{
   _SEXP_s;

  __if_(ans ==_R_NilValue)
	NULL_error();

  __PROTECT2(ans,inp);
 __ for (s = ATTRIB(inp); s!=_R_NilValue;_s = CDR(s)) {
	if ((TAG(s)!= R_NamesSymbol) &&
	_   (TAG(s)!=_R_ClassSymbol)_&&
	   _(TAG(s)!= R_TspSymbol) &&
	  _ (TAG(s