Skip to content

Commit

Permalink
Add ttr.h to use xts' naCheck() C function
Browse files Browse the repository at this point in the history
Using '#include <xtsAPI.h>' in multiple C files causes multiple
definitions of each function. Access xts' naCheck() in the same way
xts accesses zoo's zoo_lag() and zoo_coredata() C functions.

Update aroon_max() C function to use new access path.
  • Loading branch information
joshuaulrich committed Jun 23, 2018
1 parent 0a037eb commit 2a9bca6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
9 changes: 2 additions & 7 deletions src/aroon.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

/*#include <R.h>
#include <Rinternals.h>*/
#include <xtsAPI.h> /* xts exported functions */
//#include <xts.h> /* xts exported functions */
#include "ttr.h"

SEXP aroon_max (SEXP x, SEXP n) {

Expand All @@ -45,9 +42,7 @@ SEXP aroon_max (SEXP x, SEXP n) {
double *real_result = REAL(result);

/* check for non-leading NAs and get first non-NA location */
SEXP first;
//PROTECT(first = naCheck(x, ScalarLogical(TRUE))); P++; // xts.h
PROTECT(first = xtsNaCheck(x, ScalarLogical(TRUE))); P++; // xtsAPI.h
SEXP first = PROTECT(xts_na_check(x, ScalarLogical(TRUE))); P++;
int int_first = asInteger(first);
if(int_n + 1 + int_first > nr)
error("not enough non-NA values");
Expand Down
4 changes: 3 additions & 1 deletion src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/

/* Includes and defines from WRE Section 5.4.2 */
#include "ttr.h"
#include <R.h>
#include <Rinternals.h>
#include <stdlib.h> /* for NULL */
#include <R_ext/Rdynload.h>

Expand Down Expand Up @@ -78,4 +78,6 @@ void R_init_TTR(DllInfo *dll)
R_registerRoutines(dll, NULL, CallEntries, FortranEntries, NULL);
R_useDynamicSymbols(dll, FALSE);
//R_forceSymbols(dll, TRUE); /* only use R symbols (not strings) */

xts_na_check = (SEXP(*)(SEXP,SEXP)) R_GetCCallable("xts", "naCheck");
}
8 changes: 8 additions & 0 deletions src/ttr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef _TTR_H_
#define _TTR_H_

#include <Rinternals.h>

/* imported from xts */
SEXP (*xts_na_check)(SEXP, SEXP);
#endif

0 comments on commit 2a9bca6

Please sign in to comment.