RAPI
|
00001 /* 00002 * R : A Computer Language for Statistical Data Analysis 00003 * Copyright (C) 1999-2016 The R Core Team. 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU Lesser General Public License as published by 00007 * the Free Software Foundation; either version 2.1 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public License 00016 * along with this program; if not, a copy is available at 00017 * https://www.R-project.org/Licenses/ 00018 */ 00019 00020 /* From 'Writing R Extensions: 00021 00022 'these are not kept up to date and are not recommended for new projects.' 00023 00024 As from R 3.3.0 they have been adjusted to work when R_NO_REMAP is defined. 00025 */ 00026 00027 #ifndef R_DEFINES_H 00028 #define R_DEFINES_H 00029 00030 #if !defined(R_R_H) && !defined(R_S_H) 00031 /* user forgot to include R.h or S.h */ 00032 # include <R_ext/Memory.h> 00033 # include <R_ext/RS.h> 00034 #endif 00035 00036 #include <Rinternals.h> 00037 00038 /* 00039 * Much is from John Chambers' "Programming With Data". 00040 * Some of this is from Doug Bates. 00041 * 00042 * It is presented here to support a joint programming style which 00043 * will work in both R and S. In particular it helps with: 00044 * 00045 * 1. S/R <-> CORBA code. 00046 * 2. S/R <-> Java Code. 00047 * 00048 * And to hide some internal nastiness. 00049 */ 00050 00051 00052 /* 00053 * Added some macros defined in S.h from Splus 5.1 00054 */ 00055 00056 #define NULL_USER_OBJECT R_NilValue 00057 00058 #define AS_LOGICAL(x) Rf_coerceVector(x,LGLSXP) 00059 #define AS_INTEGER(x) Rf_coerceVector(x,INTSXP) 00060 #define AS_NUMERIC(x) Rf_coerceVector(x,REALSXP) 00061 #define AS_CHARACTER(x) Rf_coerceVector(x,STRSXP) 00062 #define AS_COMPLEX(x) Rf_coerceVector(x,CPLXSXP) 00063 #define AS_VECTOR(x) Rf_coerceVector(x,VECSXP) 00064 #define AS_LIST(x) Rf_coerceVector(x,VECSXP) 00065 #define AS_RAW(x) Rf_coerceVector(x,RAWSXP) 00066 00067 #ifdef USE_RINTERNALS 00068 // This is not documented to be supported, and may not be in future 00069 # define IS_LOGICAL(x) isLogical(x) 00070 # define IS_INTEGER(x) isInteger(x) 00071 # define IS_NUMERIC(x) isReal(x) 00072 # define IS_CHARACTER(x) isString(x) 00073 # define IS_COMPLEX(x) isComplex(x) 00074 #else 00075 # define IS_LOGICAL(x) Rf_isLogical(x) 00076 # define IS_INTEGER(x) Rf_isInteger(x) 00077 # define IS_NUMERIC(x) Rf_isReal(x) 00078 # define IS_CHARACTER(x) Rf_isString(x) 00079 # define IS_COMPLEX(x) Rf_isComplex(x) 00080 #endif 00081 /* NB: is this right? It means atomic or VECSXP or EXPRSXP */ 00082 #define IS_VECTOR(x) Rf_isVector(x) 00083 /* And this cannot be right: isVectorList(x)? */ 00084 #define IS_LIST(x) IS_VECTOR(x) 00085 #define IS_RAW(x) (TYPEOF(x) == RAWSXP) 00086 00087 #define NEW_LOGICAL(n) Rf_allocVector(LGLSXP,n) 00088 #define NEW_INTEGER(n) Rf_allocVector(INTSXP,n) 00089 #define NEW_NUMERIC(n) Rf_allocVector(REALSXP,n) 00090 #define NEW_CHARACTER(n) Rf_allocVector(STRSXP,n) 00091 #define NEW_COMPLEX(n) Rf_allocVector(CPLXSXP,n) 00092 #define NEW_LIST(n) Rf_allocVector(VECSXP,n) 00093 #define NEW_STRING(n) NEW_CHARACTER(n) 00094 #define NEW_RAW(n) Rf_allocVector(RAWSXP,n) 00095 00096 #define LOGICAL_POINTER(x) LOGICAL(x) 00097 #define INTEGER_POINTER(x) INTEGER(x) 00098 #define NUMERIC_POINTER(x) REAL(x) 00099 #define CHARACTER_POINTER(x) STRING_PTR(x) 00100 #define COMPLEX_POINTER(x) COMPLEX(x) 00101 /* Use of VECTOR_PTR will fail unless USE_RINTERNALS is in use 00102 This is probably unused. 00103 */ 00104 #define LIST_POINTER(x) VECTOR_PTR(x) 00105 #define RAW_POINTER(x) RAW(x) 00106 00107 /* The following are not defined in `Programming with Data' but are 00108 defined in S.h in Svr4 */ 00109 00110 /* 00111 * Note that LIST_DATA and RAW_DATA are missing. 00112 * This is consistent with Svr4. 00113 */ 00114 00115 #define LOGICAL_DATA(x) (LOGICAL(x)) 00116 #define INTEGER_DATA(x) (INTEGER(x)) 00117 #define DOUBLE_DATA(x) (REAL(x)) 00118 #define NUMERIC_DATA(x) (REAL(x)) 00119 #define CHARACTER_DATA(x) (STRING_PTR(x)) 00120 #define COMPLEX_DATA(x) (COMPLEX(x)) 00121 /* Use of VECTOR_PTR will fail unless USE_RINTERNALS is in use 00122 VECTOR_DATA seems unused, and RECURSIVE_DATA is used only in 00123 the Expat part of XML. 00124 */ 00125 #define RECURSIVE_DATA(x) (VECTOR_PTR(x)) 00126 #define VECTOR_DATA(x) (VECTOR_PTR(x)) 00127 00128 #define LOGICAL_VALUE(x) Rf_asLogical(x) 00129 #define INTEGER_VALUE(x) Rf_asInteger(x) 00130 #define NUMERIC_VALUE(x) Rf_asReal(x) 00131 #define CHARACTER_VALUE(x) CHAR(Rf_asChar(x)) 00132 #define STRING_VALUE(x) CHAR(Rf_asChar(x)) 00133 #define LIST_VALUE(x) Rf_error("the 'value' of a list object is not defined") 00134 #define RAW_VALUE(x) Rf_error("the 'value' of a raw object is not defined") 00135 00136 #define SET_ELEMENT(x, i, val) SET_VECTOR_ELT(x, i, val) 00137 #define GET_ATTR(x,what) Rf_getAttrib(x, what) 00138 #define GET_CLASS(x) Rf_getAttrib(x, R_ClassSymbol) 00139 #define GET_DIM(x) Rf_getAttrib(x, R_DimSymbol) 00140 #define GET_DIMNAMES(x) Rf_getAttrib(x, R_DimNamesSymbol) 00141 #define GET_COLNAMES(x) Rf_GetColNames(x) 00142 #define GET_ROWNAMES(x) Rf_GetRowNames(x) 00143 #define GET_LEVELS(x) Rf_getAttrib(x, R_LevelsSymbol) 00144 #define GET_TSP(x) Rf_getAttrib(x, R_TspSymbol) 00145 #define GET_NAMES(x) Rf_getAttrib(x, R_NamesSymbol) 00146 #define SET_ATTR(x, what, n) Rf_setAttrib(x, what, n) 00147 #define SET_CLASS(x, n) Rf_setAttrib(x, R_ClassSymbol, n) 00148 #define SET_DIM(x, n) Rf_setAttrib(x, R_DimSymbol, n) 00149 #define SET_DIMNAMES(x, n) Rf_setAttrib(x, R_DimNamesSymbol, n) 00150 #define SET_LEVELS(x, l) Rf_setAttrib(x, R_LevelsSymbol, l) 00151 #define SET_NAMES(x, n) Rf_setAttrib(x, R_NamesSymbol, n) 00152 /* These do not support long vectors */ 00153 #define GET_LENGTH(x) Rf_length(x) 00154 #define SET_LENGTH(x, n) (x = Rf_lengthgets(x, n)) 00155 00156 #define GET_SLOT(x, what) R_do_slot(x, what) 00157 #define SET_SLOT(x, what, value) R_do_slot_assign(x, what, value) 00158 00159 #define MAKE_CLASS(what) R_do_MAKE_CLASS(what) 00160 /* NEW_OBJECT is recommended; NEW is for green book compatibility */ 00161 #define NEW_OBJECT(class_def) R_do_new_object(class_def) 00162 #define NEW(class_def) R_do_new_object(class_def) 00163 00164 #define s_object SEXPREC 00165 #define S_EVALUATOR 00166 00167 /* These conflict with definitions in R_ext/Boolean.h, 00168 but spatstat relies on them in a C file */ 00169 #ifdef __cplusplus 00170 # ifndef R_EXT_BOOLEAN_H_ 00171 # ifndef TRUE 00172 # define TRUE 1 00173 # endif 00174 # ifndef FALSE 00175 # define FALSE 0 00176 # endif 00177 # endif 00178 #else 00179 # ifndef TRUE 00180 # define TRUE 1 00181 # endif 00182 # ifndef FALSE 00183 # define FALSE 0 00184 # endif 00185 #endif 00186 00187 #define COPY_TO_USER_STRING(x) mkChar(x) 00188 #define CREATE_STRING_VECTOR(x) mkChar(x) 00189 00190 #define CREATE_FUNCTION_CALL(name, argList) createFunctionCall(name, argList) 00191 00192 #define EVAL(x) eval(x,R_GlobalEnv) 00193 00194 00195 #endif