39 #if !defined(R_R_H) && !defined(R_S_H)
41 # include <R_ext/Memory.h>
42 # include <R_ext/RS.h>
69 #define NULL_USER_OBJECT R_NilValue
71 #define AS_LOGICAL(x) coerceVector(x,LGLSXP)
72 #define AS_INTEGER(x) coerceVector(x,INTSXP)
73 #define AS_NUMERIC(x) coerceVector(x,REALSXP)
74 #define AS_CHARACTER(x) coerceVector(x,STRSXP)
75 #define AS_COMPLEX(x) coerceVector(x,CPLXSXP)
76 #define AS_VECTOR(x) coerceVector(x,VECSXP)
77 #define AS_LIST(x) coerceVector(x,VECSXP)
78 #define AS_RAW(x) coerceVector(x,RAWSXP)
80 #define IS_LOGICAL(x) Rf_isLogical(x)
81 #define IS_INTEGER(x) Rf_isInteger(x)
82 #define IS_NUMERIC(x) Rf_isReal(x)
83 #define IS_CHARACTER(x) Rf_isString(x)
84 #define IS_COMPLEX(x) Rf_isComplex(x)
86 #define IS_VECTOR(x) Rf_isVector(x)
88 #define IS_LIST(x) IS_VECTOR(x)
89 #define IS_RAW(x) (TYPEOF(x) == RAWSXP)
91 #define NEW_LOGICAL(n) Rf_allocVector(LGLSXP,n)
92 #define NEW_INTEGER(n) Rf_allocVector(INTSXP,n)
93 #define NEW_NUMERIC(n) Rf_allocVector(REALSXP,n)
94 #define NEW_CHARACTER(n) Rf_allocVector(STRSXP,n)
95 #define NEW_COMPLEX(n) Rf_allocVector(CPLXSXP,n)
96 #define NEW_LIST(n) Rf_allocVector(VECSXP,n)
97 #define NEW_STRING(n) NEW_CHARACTER(n)
98 #define NEW_RAW(n) Rf_allocVector(RAWSXP,n)
100 #define LOGICAL_POINTER(x) LOGICAL(x)
101 #define INTEGER_POINTER(x) INTEGER(x)
102 #define NUMERIC_POINTER(x) REAL(x)
103 #define COMPLEX_POINTER(x) COMPLEX(x)
104 #define RAW_POINTER(x) RAW(x)
114 #define LOGICAL_DATA(x) (LOGICAL(x))
115 #define INTEGER_DATA(x) (INTEGER(x))
116 #define DOUBLE_DATA(x) (REAL(x))
117 #define NUMERIC_DATA(x) (REAL(x))
118 #define COMPLEX_DATA(x) (COMPLEX(x))
120 #define LOGICAL_VALUE(x) asLogical(x)
121 #define INTEGER_VALUE(x) asInteger(x)
122 #define NUMERIC_VALUE(x) asReal(x)
123 #define CHARACTER_VALUE(x) CHAR(asChar(x))
124 #define STRING_VALUE(x) CHAR(asChar(x))
125 #define LIST_VALUE(x) error("the 'value' of a list object is not defined")
126 #define RAW_VALUE(x) error("the 'value' of a raw object is not defined")
128 #define SET_ELEMENT(x, i, val) SET_VECTOR_ELT(x, i, val)
129 #define GET_ATTR(x,what) getAttrib(x, what)
130 #define GET_CLASS(x) getAttrib(x, R_ClassSymbol)
131 #define GET_DIM(x) getAttrib(x, R_DimSymbol)
132 #define GET_DIMNAMES(x) getAttrib(x, R_DimNamesSymbol)
133 #define GET_COLNAMES(x) GetColNames(x)
134 #define GET_ROWNAMES(x) GetRowNames(x)
135 #define GET_LEVELS(x) getAttrib(x, R_LevelsSymbol)
136 #define GET_TSP(x) getAttrib(x, R_TspSymbol)
137 #define GET_NAMES(x) getAttrib(x, R_NamesSymbol)
138 #define SET_ATTR(x, what, n) setAttrib(x, what, n)
139 #define SET_CLASS(x, n) setAttrib(x, R_ClassSymbol, n)
140 #define SET_DIM(x, n) setAttrib(x, R_DimSymbol, n)
141 #define SET_DIMNAMES(x, n) setAttrib(x, R_DimNamesSymbol, n)
142 #define SET_LEVELS(x, l) setAttrib(x, R_LevelsSymbol, l)
143 #define SET_NAMES(x, n) setAttrib(x, R_NamesSymbol, n)
144 #define GET_LENGTH(x) length(x)
145 #define SET_LENGTH(x, n) (x = lengthgets(x, n))
147 #define GET_SLOT(x, what) R_do_slot(x, what)
148 #define SET_SLOT(x, what, value) R_do_slot_assign(x, what, value)
150 #define MAKE_CLASS(what) R_do_MAKE_CLASS(what)
152 #define NEW_OBJECT(class_def) R_do_new_object(class_def)
153 #define NEW(class_def) R_do_new_object(class_def)
155 #define s_object SEXPREC
164 #define COPY_TO_USER_STRING(x) mkChar(x)
165 #define CREATE_STRING_VECTOR(x) mkChar(x)
167 #define CREATE_FUNCTION_CALL(name, argList) createFunctionCall(name, argList)
169 #define EVAL(x) eval(x,R_GlobalEnv)