From a3a0f8b3ca0747c5fe2f595b28330fda15dea3a5 Mon Sep 17 00:00:00 2001 From: dereckmezquita Date: Mon, 8 Jul 2024 00:46:27 -0500 Subject: [PATCH] Clean up and use convention of basic Rcpp package. --- .github/workflows/pkgdown.yml | 5 - .gitignore | 4 - DESCRIPTION | 6 +- NAMESPACE | 2 - R/{cpp.R => RcppExports.R} | 10 +- man/bb.Rd | 4 +- man/ema.Rd | 2 +- man/macd.Rd | 2 +- man/mom.Rd | 2 +- man/monte_carlo.Rd | 2 +- man/roc.Rd | 2 +- man/rsi.Rd | 2 +- man/sma.Rd | 2 +- src/Makevars.in | 2 - src/RcppExports.cpp | 117 ++++++++++++++++++ src/bb-bollinger-bands.cpp | 17 ++- src/bb-bollinger-bands.h | 4 +- src/ema-exponential-moving-average.cpp | 7 ++ src/ema-exponential-moving-average.h | 4 +- ...-moving-average-convergence-divergence.cpp | 9 ++ ...cd-moving-average-convergence-divergence.h | 4 +- src/mom-momentum.cpp | 6 + src/mom-momentum.h | 4 +- src/monte_carlo.cpp | 8 ++ src/roc-rate-of-change.cpp | 7 ++ src/roc-rate-of-change.h | 4 +- src/rsi-relative-strength-index.cpp | 7 ++ src/rsi-relative-strength-index.h | 4 +- src/sma-simple-moving-average.cpp | 8 +- src/sma-simple-moving-average.h | 4 +- tools/debug-build.R | 59 --------- 31 files changed, 209 insertions(+), 111 deletions(-) rename R/{cpp.R => RcppExports.R} (94%) delete mode 100644 src/Makevars.in create mode 100644 src/RcppExports.cpp delete mode 100644 tools/debug-build.R diff --git a/.github/workflows/pkgdown.yml b/.github/workflows/pkgdown.yml index 4c45cac..a9cf3e1 100644 --- a/.github/workflows/pkgdown.yml +++ b/.github/workflows/pkgdown.yml @@ -32,11 +32,6 @@ jobs: sudo apt-get update sudo apt-get install -y libcurl4-openssl-dev libssl-dev libxml2-dev libgit2-dev - - name: Fix DESCRIPTION file - run: | - sed -i -e '$a\' DESCRIPTION - cat DESCRIPTION - - name: Install R dependencies run: | install.packages(c("devtools", "renv", "Rcpp", "pkgdown", "rcmdcheck", "remotes")) diff --git a/.gitignore b/.gitignore index 6c8b366..0ec5a2f 100644 --- a/.gitignore +++ b/.gitignore @@ -13,10 +13,6 @@ deprecated/ .RData .Ruserdata -# RcppExports -RcppExports.cpp -RcppExports.R - # History files .Rhistory .Rapp.history diff --git a/DESCRIPTION b/DESCRIPTION index 90c2932..f6f8873 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -14,8 +14,8 @@ Depends: R (>= 4.1.0) LinkingTo: Rcpp Imports: ggplot2 (>= 3.4.0), - data.table, - Rcpp + Rcpp (>= 1.0.12), + data.table License: MIT + file LICENSE Encoding: UTF-8 LazyData: true @@ -32,4 +32,4 @@ Suggests: testthat (>= 3.0.0) Remotes: dereckmezquita/kucoin -Config/testthat/edition: 3 \ No newline at end of file +Config/testthat/edition: 3 diff --git a/NAMESPACE b/NAMESPACE index a874e22..f72b118 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -19,6 +19,4 @@ export(theme_dereck_dark) export(theme_dereck_light) import(data.table) import(ggplot2) -importFrom(Rcpp,evalCpp) importFrom(ggplot2,'%+replace%') -useDynLib(dmplot, .registration = TRUE) diff --git a/R/cpp.R b/R/RcppExports.R similarity index 94% rename from R/cpp.R rename to R/RcppExports.R index c2dc354..7574a24 100644 --- a/R/cpp.R +++ b/R/RcppExports.R @@ -1,8 +1,5 @@ -# Wrapper functions for C++ code in dmplot package - -#' @useDynLib dmplot, .registration = TRUE -#' @importFrom Rcpp evalCpp -NULL +# Generated by using Rcpp::compileAttributes() -> do not edit by hand +# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 #' Bollinger Bands #' @@ -11,7 +8,7 @@ NULL #' @param sd The number of standard deviations for the bands #' @return A list containing the lower band, moving average, upper band, and percentage B #' @export -bb <- function(price, n, sd = 2) { +bb <- function(price, n, sd = 2L) { .Call('_dmplot_bb', PACKAGE = 'dmplot', price, n, sd) } @@ -92,3 +89,4 @@ rsi <- function(price, n, method = 'e') { sma <- function(price, n) { .Call('_dmplot_sma', PACKAGE = 'dmplot', price, n) } + diff --git a/man/bb.Rd b/man/bb.Rd index 071da7a..c64ec2a 100644 --- a/man/bb.Rd +++ b/man/bb.Rd @@ -1,10 +1,10 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/cpp.R +% Please edit documentation in R/RcppExports.R \name{bb} \alias{bb} \title{Bollinger Bands} \usage{ -bb(price, n, sd = 2) +bb(price, n, sd = 2L) } \arguments{ \item{price}{A numeric vector of prices} diff --git a/man/ema.Rd b/man/ema.Rd index 6729b7c..76c8dfd 100644 --- a/man/ema.Rd +++ b/man/ema.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/cpp.R +% Please edit documentation in R/RcppExports.R \name{ema} \alias{ema} \title{Exponential Moving Average} diff --git a/man/macd.Rd b/man/macd.Rd index 79afb3e..4e63f1e 100644 --- a/man/macd.Rd +++ b/man/macd.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/cpp.R +% Please edit documentation in R/RcppExports.R \name{macd} \alias{macd} \title{Moving Average Convergence Divergence (MACD)} diff --git a/man/mom.Rd b/man/mom.Rd index c556747..7f17b2c 100644 --- a/man/mom.Rd +++ b/man/mom.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/cpp.R +% Please edit documentation in R/RcppExports.R \name{mom} \alias{mom} \title{Momentum} diff --git a/man/monte_carlo.Rd b/man/monte_carlo.Rd index a663224..14e102f 100644 --- a/man/monte_carlo.Rd +++ b/man/monte_carlo.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/cpp.R +% Please edit documentation in R/RcppExports.R \name{monte_carlo} \alias{monte_carlo} \title{Monte Carlo Simulation} diff --git a/man/roc.Rd b/man/roc.Rd index c731016..afdeee0 100644 --- a/man/roc.Rd +++ b/man/roc.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/cpp.R +% Please edit documentation in R/RcppExports.R \name{roc} \alias{roc} \title{Rate of Change (ROC)} diff --git a/man/rsi.Rd b/man/rsi.Rd index d98249e..4feb021 100644 --- a/man/rsi.Rd +++ b/man/rsi.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/cpp.R +% Please edit documentation in R/RcppExports.R \name{rsi} \alias{rsi} \title{Relative Strength Index (RSI)} diff --git a/man/sma.Rd b/man/sma.Rd index 5d31bae..2714f9b 100644 --- a/man/sma.Rd +++ b/man/sma.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/cpp.R +% Please edit documentation in R/RcppExports.R \name{sma} \alias{sma} \title{Simple Moving Average (SMA)} diff --git a/src/Makevars.in b/src/Makevars.in deleted file mode 100644 index ad41580..0000000 --- a/src/Makevars.in +++ /dev/null @@ -1,2 +0,0 @@ -PKG_CPPFLAGS = @PKG_CPPFLAGS@ -PKG_LIBS = @PKG_LIBS@ diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp new file mode 100644 index 0000000..7659891 --- /dev/null +++ b/src/RcppExports.cpp @@ -0,0 +1,117 @@ +// Generated by using Rcpp::compileAttributes() -> do not edit by hand +// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 + +#include + +using namespace Rcpp; + +#ifdef RCPP_USE_GLOBAL_ROSTREAM +Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get(); +Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); +#endif + +// bb +Rcpp::List bb(std::vector price, int n, int sd); +RcppExport SEXP _dmplot_bb(SEXP priceSEXP, SEXP nSEXP, SEXP sdSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< std::vector >::type price(priceSEXP); + Rcpp::traits::input_parameter< int >::type n(nSEXP); + Rcpp::traits::input_parameter< int >::type sd(sdSEXP); + rcpp_result_gen = Rcpp::wrap(bb(price, n, sd)); + return rcpp_result_gen; +END_RCPP +} +// ema +std::vector ema(std::vector price, int n, bool wilder); +RcppExport SEXP _dmplot_ema(SEXP priceSEXP, SEXP nSEXP, SEXP wilderSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< std::vector >::type price(priceSEXP); + Rcpp::traits::input_parameter< int >::type n(nSEXP); + Rcpp::traits::input_parameter< bool >::type wilder(wilderSEXP); + rcpp_result_gen = Rcpp::wrap(ema(price, n, wilder)); + return rcpp_result_gen; +END_RCPP +} +// macd +List macd(std::vector price, int s, int l, int k, bool percent); +RcppExport SEXP _dmplot_macd(SEXP priceSEXP, SEXP sSEXP, SEXP lSEXP, SEXP kSEXP, SEXP percentSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< std::vector >::type price(priceSEXP); + Rcpp::traits::input_parameter< int >::type s(sSEXP); + Rcpp::traits::input_parameter< int >::type l(lSEXP); + Rcpp::traits::input_parameter< int >::type k(kSEXP); + Rcpp::traits::input_parameter< bool >::type percent(percentSEXP); + rcpp_result_gen = Rcpp::wrap(macd(price, s, l, k, percent)); + return rcpp_result_gen; +END_RCPP +} +// mom +std::vector mom(std::vector price, int n); +RcppExport SEXP _dmplot_mom(SEXP priceSEXP, SEXP nSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< std::vector >::type price(priceSEXP); + Rcpp::traits::input_parameter< int >::type n(nSEXP); + rcpp_result_gen = Rcpp::wrap(mom(price, n)); + return rcpp_result_gen; +END_RCPP +} +// monte_carlo +Rcpp::List monte_carlo(double seed_price, double daily_vol, int num_sims, int num_days); +RcppExport SEXP _dmplot_monte_carlo(SEXP seed_priceSEXP, SEXP daily_volSEXP, SEXP num_simsSEXP, SEXP num_daysSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< double >::type seed_price(seed_priceSEXP); + Rcpp::traits::input_parameter< double >::type daily_vol(daily_volSEXP); + Rcpp::traits::input_parameter< int >::type num_sims(num_simsSEXP); + Rcpp::traits::input_parameter< int >::type num_days(num_daysSEXP); + rcpp_result_gen = Rcpp::wrap(monte_carlo(seed_price, daily_vol, num_sims, num_days)); + return rcpp_result_gen; +END_RCPP +} +// roc +std::vector roc(std::vector price, int n, char type); +RcppExport SEXP _dmplot_roc(SEXP priceSEXP, SEXP nSEXP, SEXP typeSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< std::vector >::type price(priceSEXP); + Rcpp::traits::input_parameter< int >::type n(nSEXP); + Rcpp::traits::input_parameter< char >::type type(typeSEXP); + rcpp_result_gen = Rcpp::wrap(roc(price, n, type)); + return rcpp_result_gen; +END_RCPP +} +// rsi +std::vector rsi(std::vector price, int n, char method); +RcppExport SEXP _dmplot_rsi(SEXP priceSEXP, SEXP nSEXP, SEXP methodSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< std::vector >::type price(priceSEXP); + Rcpp::traits::input_parameter< int >::type n(nSEXP); + Rcpp::traits::input_parameter< char >::type method(methodSEXP); + rcpp_result_gen = Rcpp::wrap(rsi(price, n, method)); + return rcpp_result_gen; +END_RCPP +} +// sma +std::vector sma(std::vector price, int n); +RcppExport SEXP _dmplot_sma(SEXP priceSEXP, SEXP nSEXP) { +BEGIN_RCPP + Rcpp::RObject rcpp_result_gen; + Rcpp::RNGScope rcpp_rngScope_gen; + Rcpp::traits::input_parameter< std::vector >::type price(priceSEXP); + Rcpp::traits::input_parameter< int >::type n(nSEXP); + rcpp_result_gen = Rcpp::wrap(sma(price, n)); + return rcpp_result_gen; +END_RCPP +} diff --git a/src/bb-bollinger-bands.cpp b/src/bb-bollinger-bands.cpp index a09e154..feed248 100644 --- a/src/bb-bollinger-bands.cpp +++ b/src/bb-bollinger-bands.cpp @@ -1,11 +1,20 @@ #include -// [[Rcpp::depends(Rcpp)]] - #include -#include "sma-simple-moving-average.h" using namespace Rcpp; +#include "bb-bollinger-bands.h" +#include "sma-simple-moving-average.h" + +// https://gallery.rcpp.org/articles/creating-a-datatable-in-rcpp/ + +//' Bollinger Bands +//' +//' @param price A numeric vector of prices +//' @param n The period for the moving average +//' @param sd The number of standard deviations for the bands +//' @return A list containing the lower band, moving average, upper band, and percentage B +//' @export // [[Rcpp::export]] Rcpp::List bb(std::vector price, int n, int sd = 2) { // calculate the simple moving average @@ -45,5 +54,3 @@ Rcpp::List bb(std::vector price, int n, int sd = 2) { return result; } - -// https://gallery.rcpp.org/articles/creating-a-datatable-in-rcpp/ diff --git a/src/bb-bollinger-bands.h b/src/bb-bollinger-bands.h index ae4e32b..96d8129 100644 --- a/src/bb-bollinger-bands.h +++ b/src/bb-bollinger-bands.h @@ -1,5 +1,5 @@ -#ifndef KUCOIN_BB_BOLLINGER_BANDS_H -#define KUCOIN_BB_BOLLINGER_BANDS_H +#ifndef DMPLOT_BB_BOLLINGER_BANDS_H +#define DMPLOT_BB_BOLLINGER_BANDS_H Rcpp::List bb(std::vector price, int n, int sd); diff --git a/src/ema-exponential-moving-average.cpp b/src/ema-exponential-moving-average.cpp index d1e0759..4553276 100644 --- a/src/ema-exponential-moving-average.cpp +++ b/src/ema-exponential-moving-average.cpp @@ -10,6 +10,13 @@ using namespace Rcpp; // https://github.com/joshuaulrich/TTR/blob/master/src/moving_averages.c +//' Exponential Moving Average +//' +//' @param price A numeric vector of prices +//' @param n The period for the EMA +//' @param wilder Whether to use Wilder's smoothing +//' @return A numeric vector containing the EMA values +//' @export // [[Rcpp::export]] std::vector ema(std::vector price, int n, bool wilder = false) { // define beta diff --git a/src/ema-exponential-moving-average.h b/src/ema-exponential-moving-average.h index 75ad494..f9bce63 100644 --- a/src/ema-exponential-moving-average.h +++ b/src/ema-exponential-moving-average.h @@ -1,5 +1,5 @@ -#ifndef KUCOIN_EMA_EXPONENTIAL_MOVING_AVEREAGE_H -#define KUCOIN_EMA_EXPONENTIAL_MOVING_AVEREAGE_H +#ifndef DMPLOT_EMA_EXPONENTIAL_MOVING_AVEREAGE_H +#define DMPLOT_EMA_EXPONENTIAL_MOVING_AVEREAGE_H std::vector ema(std::vector price, int n, bool wilder = false); diff --git a/src/macd-moving-average-convergence-divergence.cpp b/src/macd-moving-average-convergence-divergence.cpp index 76ffce3..880431f 100644 --- a/src/macd-moving-average-convergence-divergence.cpp +++ b/src/macd-moving-average-convergence-divergence.cpp @@ -6,6 +6,15 @@ using namespace Rcpp; +//' Moving Average Convergence Divergence (MACD) +//' +//' @param price A numeric vector of prices +//' @param s The short-term period +//' @param l The long-term period +//' @param k The signal line period +//' @param percent Whether to return the MACD as a percentage +//' @return A list containing the MACD and signal line values +//' @export // [[Rcpp::export]] List macd(std::vector price, int s, int l, int k, bool percent = true) { std::vector mavg_fast = ema(price, s); diff --git a/src/macd-moving-average-convergence-divergence.h b/src/macd-moving-average-convergence-divergence.h index 8b3c49b..244c7b4 100644 --- a/src/macd-moving-average-convergence-divergence.h +++ b/src/macd-moving-average-convergence-divergence.h @@ -1,5 +1,5 @@ -#ifndef KUCOIN_MACD_MOVING_AVERAGE_CONVERGENCE_DIVERGENCE_H -#define KUCOIN_MACD_MOVING_AVERAGE_CONVERGENCE_DIVERGENCE_H +#ifndef DMPLOT_MACD_MOVING_AVERAGE_CONVERGENCE_DIVERGENCE_H +#define DMPLOT_MACD_MOVING_AVERAGE_CONVERGENCE_DIVERGENCE_H Rcpp::List macd(std::vector price, int s, int l, int k, bool percent); diff --git a/src/mom-momentum.cpp b/src/mom-momentum.cpp index 37d716a..1353d40 100644 --- a/src/mom-momentum.cpp +++ b/src/mom-momentum.cpp @@ -7,6 +7,12 @@ using namespace Rcpp; // https://bookdown.org/kochiuyu/technical-analysis-with-r-second-edition2/momentum.html // M_t(n) = P_t - P_(t-n) +//' Momentum +//' +//' @param price A numeric vector of prices +//' @param n The period for momentum calculation +//' @return A numeric vector containing the momentum values +//' @export // [[Rcpp::export]] std::vector mom(std::vector price, int n) { std::vector result(price.size(), NA_REAL); diff --git a/src/mom-momentum.h b/src/mom-momentum.h index 5b5240f..60d4c33 100644 --- a/src/mom-momentum.h +++ b/src/mom-momentum.h @@ -1,5 +1,5 @@ -#ifndef KUCOIN_MOM_MOMENTUM_H -#define KUCOIN_MOM_MOMENTUM_H +#ifndef DMPLOT_MOM_MOMENTUM_H +#define DMPLOT_MOM_MOMENTUM_H std::vector mom(std::vector price, int n); diff --git a/src/monte_carlo.cpp b/src/monte_carlo.cpp index 9193b40..1c416db 100644 --- a/src/monte_carlo.cpp +++ b/src/monte_carlo.cpp @@ -1,5 +1,13 @@ #include +//' Monte Carlo Simulation +//' +//' @param seed_price The starting price +//' @param daily_vol The daily volatility +//' @param num_sims The number of simulations to run +//' @param num_days The number of days to simulate +//' @return A list containing the simulation results and end prices +//' @export // [[Rcpp::export]] Rcpp::List monte_carlo(double seed_price, double daily_vol, int num_sims, int num_days) { int total_rows = num_sims * num_days; diff --git a/src/roc-rate-of-change.cpp b/src/roc-rate-of-change.cpp index 1113089..ffdfd45 100644 --- a/src/roc-rate-of-change.cpp +++ b/src/roc-rate-of-change.cpp @@ -11,6 +11,13 @@ using namespace Rcpp; // continuous type - TTR uses continuous by default // ROC_t(K) = log(P_t) - log(P_(t-K)) +//' Rate of Change (ROC) +//' +//' @param price A numeric vector of prices +//' @param n The period for ROC calculation +//' @param type The type of ROC calculation: 'c' for continuous (default) or 'd' for discrete +//' @return A numeric vector containing the ROC values +//' @export // [[Rcpp::export]] std::vector roc(std::vector price, int n, char type = 'c') { std::vector result(price.size(), NA_REAL); diff --git a/src/roc-rate-of-change.h b/src/roc-rate-of-change.h index 4cc966e..c87a21a 100644 --- a/src/roc-rate-of-change.h +++ b/src/roc-rate-of-change.h @@ -1,5 +1,5 @@ -#ifndef KUCOIN_ROC_RATE_OF_CHANGE_H -#define KUCOIN_ROC_RATE_OF_CHANGE_H +#ifndef DMPLOT_ROC_RATE_OF_CHANGE_H +#define DMPLOT_ROC_RATE_OF_CHANGE_H std::vector roc(std::vector price, int n, char type); diff --git a/src/rsi-relative-strength-index.cpp b/src/rsi-relative-strength-index.cpp index 3d20bce..dcf25d5 100644 --- a/src/rsi-relative-strength-index.cpp +++ b/src/rsi-relative-strength-index.cpp @@ -7,6 +7,13 @@ using namespace Rcpp; +//' Relative Strength Index (RSI) +//' +//' @param price A numeric vector of prices +//' @param n The period for RSI calculation +//' @param method The method for average calculation: 'e' for EMA (default) or 's' for SMA +//' @return A numeric vector containing the RSI values +//' @export // [[Rcpp::export]] std::vector rsi(std::vector price, int n, char method = 'e') { int price_length = price.size(); diff --git a/src/rsi-relative-strength-index.h b/src/rsi-relative-strength-index.h index 1380142..d6bb136 100644 --- a/src/rsi-relative-strength-index.h +++ b/src/rsi-relative-strength-index.h @@ -1,5 +1,5 @@ -#ifndef KUCOIN_RSI_RELATIVE_STRENGTH_INDEX_H -#define KUCOIN_RSI_RELATIVE_STRENGTH_INDEX_H +#ifndef DMPLOT_RSI_RELATIVE_STRENGTH_INDEX_H +#define DMPLOT_RSI_RELATIVE_STRENGTH_INDEX_H std::vector rsi(std::vector price, int n, char method); diff --git a/src/sma-simple-moving-average.cpp b/src/sma-simple-moving-average.cpp index 736cad9..1898678 100644 --- a/src/sma-simple-moving-average.cpp +++ b/src/sma-simple-moving-average.cpp @@ -1,10 +1,14 @@ #include -// [[Rcpp::interfaces(r, cpp)]] - #include using namespace Rcpp; +//' Simple Moving Average (SMA) +//' +//' @param price A numeric vector of prices +//' @param n The period for SMA calculation +//' @return A numeric vector containing the SMA values +//' @export // [[Rcpp::export]] std::vector sma(std::vector price, int n) { // pre-allocate the vector with NA values diff --git a/src/sma-simple-moving-average.h b/src/sma-simple-moving-average.h index 8f9a2ca..b3d135e 100644 --- a/src/sma-simple-moving-average.h +++ b/src/sma-simple-moving-average.h @@ -1,5 +1,5 @@ -#ifndef KUCOIN_SMA_SIMPLE_MOVING_AVERAGE_H -#define KUCOIN_SMA_SIMPLE_MOVING_AVERAGE_H +#ifndef DMPLOT_SMA_SIMPLE_MOVING_AVERAGE_H +#define DMPLOT_SMA_SIMPLE_MOVING_AVERAGE_H std::vector sma(std::vector price, int n); diff --git a/tools/debug-build.R b/tools/debug-build.R deleted file mode 100644 index ec8ff8f..0000000 --- a/tools/debug-build.R +++ /dev/null @@ -1,59 +0,0 @@ -# Debug script for dmplot package build - -library(devtools) - -# Check R version and installed packages -cat("R version:\n") -print(R.version) - -cat("\nInstalled packages:\n") -print(installed.packages()[, c("Package", "Version")]) - -# Check if required system libraries are installed -system_libs <- c("libcurl4-openssl-dev", "libssl-dev", "libxml2-dev", "libgit2-dev") -for (lib in system_libs) { - status <- system(paste("dpkg -s", lib, ">/dev/null 2>&1"), intern = TRUE) - cat(sprintf("%s installed: %s\n", lib, ifelse(status == 0, "Yes", "No"))) -} - -# Attempt to load and build the package -cat("\nAttempting to load and build the package:\n") -tryCatch({ - load_all() - document() - build() -}, error = function(e) { - cat("Error occurred during package build:\n") - print(e) -}) - -# Check for common issues -cat("\nChecking for common issues:\n") - -if (!file.exists("DESCRIPTION")) { - cat("DESCRIPTION file is missing.\n") -} else { - cat("DESCRIPTION file exists.\n") -} - -if (!dir.exists("R")) { - cat("R directory is missing.\n") -} else { - cat("R directory exists.\n") -} - -if (!dir.exists("src")) { - cat("src directory is missing.\n") -} else { - cat("src directory exists.\n") - cpp_files <- list.files("src", pattern = "\\.cpp$") - if (length(cpp_files) == 0) { - cat("No .cpp files found in src directory.\n") - } else { - cat("Found", length(cpp_files), ".cpp files in src directory.\n") - } -} - -# Additional checks can be added here - -cat("\nDebug script completed.\n") \ No newline at end of file