From f09b272e46c3686bdafef3dff2d462d1095a36cf Mon Sep 17 00:00:00 2001 From: Simon Garnier Date: Thu, 10 Oct 2024 15:43:54 -0400 Subject: [PATCH] Fix CRAN NO_REMAP error --- .Rbuildignore | 1 + .gitignore | 1 + DESCRIPTION | 6 ++-- NEWS.md | 12 +++++++ R/CEC-package.R | 73 +++---------------------------------------- R/cec.R | 14 ++++----- R/utils.R | 69 ++++++++++++++++++++++++++++++++++++++++ man/CEC-package.Rd | 2 ++ man/Tset.Rd | 2 +- man/cec.Rd | 8 ++--- man/fourGaussians.Rd | 2 +- man/mixShapes.Rd | 2 +- man/threeGaussians.Rd | 2 +- src/cec_r.cpp | 12 +++---- src/cov.h | 2 +- src/r_result.cpp | 16 +++++----- src/r_utils.h | 16 +++++----- 17 files changed, 130 insertions(+), 110 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index fba9064..c4e5168 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -11,3 +11,4 @@ cran-comments.md ^CRAN-SUBMISSION$ ^codecov\.yml$ revdep +.vscode \ No newline at end of file diff --git a/.gitignore b/.gitignore index 56f5e50..611b2f9 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,4 @@ src/models/*.o src/models/*.so src/models/*.dll docs +.vscode/settings.json diff --git a/DESCRIPTION b/DESCRIPTION index 1bed299..f41a135 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: CEC Type: Package Title: Cross-Entropy Clustering -Version: 0.11.1 -Date: 2024-01-08 +Version: 0.11.2 +Date: 2024-10-10 Authors@R: c( person("Kamieniecki", "Konrad", email = "konrad.kamieniecki@alumni.uj.edu.pl", role = c("aut")), @@ -30,6 +30,6 @@ Imports: utils NeedsCompilation: yes License: GPL-3 -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.2 Suggests: covr diff --git a/NEWS.md b/NEWS.md index 4a7dde8..244a9a6 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,15 @@ +# CEC v0.11.2 + +## New features + +* N/A. + +## Minor improvements and fixes + +* Fixing CRAN NO_REMAP error with R > 4.5.0. + +--- + # CEC v0.11.1 ## New features diff --git a/R/CEC-package.R b/R/CEC-package.R index 2a6f981..844fc30 100644 --- a/R/CEC-package.R +++ b/R/CEC-package.R @@ -14,75 +14,10 @@ #' #' @seealso \code{\link{cec}} #' -#' @keywords package multivariate cluster models +#' @keywords internal package multivariate cluster models #' -NULL - - -#' @title Four Gaussian Clusters -#' -#' @description Matrix of 2-dimensional points forming four Gaussian clusters. -#' -#' @name fourGaussians -#' -#' @docType data -#' -#' @keywords datasets -#' -#' @examples -#' data(fourGaussians) -#' plot(fourGaussians, cex = 0.5, pch = 19); -#' -NULL - +"_PACKAGE" -#' @title Three Gaussian Clusters -#' -#' @description Matrix of 2-dimensional points forming three Gaussian clusters. -#' -#' @name threeGaussians -#' -#' @docType data -#' -#' @keywords datasets -#' -#' @examples -#' data(threeGaussians) -#' plot(threeGaussians, cex = 0.5, pch = 19); -#' -NULL - - -#' @title Mixed Shapes Clusters -#' -#' @description Matrix of 2-dimensional points that form circular and elliptical -#' patterns. -#' -#' @name mixShapes -#' -#' @docType data -#' -#' @keywords datasets -#' -#' @examples -#' data(mixShapes) -#' plot(mixShapes, cex = 0.5, pch = 19); -#' -NULL - - -#' @title T-Shaped Clusters -#' -#' @description Matrix of 2-dimensional points that form the letter T. -#' -#' @name Tset -#' -#' @docType data -#' -#' @keywords datasets -#' -#' @examples -#' data(Tset) -#' plot(Tset, cex = 0.5, pch = 19); -#' +## usethis namespace: start +## usethis namespace: end NULL diff --git a/R/cec.R b/R/cec.R index eaf9996..4feab5e 100644 --- a/R/cec.R +++ b/R/cec.R @@ -26,8 +26,8 @@ #' Possible values are: "covariance", "fixedr", "spherical", "diagonal", #' "eigenvalues", "all" (default). #' -#' Currently, if the \code{centers} argument is a vector, only a single type can -#' be used. +#' Currently, if the \code{centers} argument is a vector, only a single type +#' can be used. #' #' @param iter.max The maximum number of iterations of the clustering algorithm. #' @@ -62,8 +62,8 @@ #' visible in the results as NA in the "centers" matrix (as well as the #' corresponding values in the list of covariances). #' -#' @param interactive If \code{TRUE}, the result of clustering will be plotted after -#' every iteration. +#' @param interactive If \code{TRUE}, the result of clustering will be plotted +#' after every iteration. #' #' @param threads The number of threads to use or "auto" to use the default #' number of threads (usually the number of available processing units/cores) @@ -344,7 +344,7 @@ cec <- function(x, card.min <- max(card.min, n + 1) k <- max(var.centers) - startTime <- proc.time() + # startTime <- proc.time() centers.r <- list(init.method = init.method.name, var.centers = as.integer(var.centers), @@ -378,7 +378,7 @@ cec <- function(x, } k.final <- nrow(Z$centers) - execution.time <- as.vector((proc.time() - startTime))[3] + # execution.time <- as.vector((proc.time() - startTime))[3] Z$centers[is.nan(Z$centers)] <- NA tab <- tabulate(Z$cluster) probability <- vapply(tab, function(c.card) { @@ -427,7 +427,7 @@ cec <- function(x, structure( list(data = x, cluster = Z$cluster, centers = Z$centers, probability = probability, cost.function = Z$energy, - nclusters = Z$nclusters, iterations = Z$iterations, time = execution.time, covariances = Z$covariances, + nclusters = Z$nclusters, iterations = Z$iterations, covariances = Z$covariances, covariances.model = covariances.model, means.model = means.model), class = "cec") } diff --git a/R/utils.R b/R/utils.R index cb1d2ca..5199454 100644 --- a/R/utils.R +++ b/R/utils.R @@ -127,3 +127,72 @@ mouseset <- function(n = 4000, r.head = 2, r.left.ear = 1.1, r.right.ear = 1.1, M } + + +#' @title Four Gaussian Clusters +#' +#' @description Matrix of 2-dimensional points forming four Gaussian clusters. +#' +#' @name fourGaussians +#' +#' @docType data +#' +#' @keywords datasets +#' +#' @examples +#' data(fourGaussians) +#' plot(fourGaussians, cex = 0.5, pch = 19); +#' +NULL + + +#' @title Three Gaussian Clusters +#' +#' @description Matrix of 2-dimensional points forming three Gaussian clusters. +#' +#' @name threeGaussians +#' +#' @docType data +#' +#' @keywords datasets +#' +#' @examples +#' data(threeGaussians) +#' plot(threeGaussians, cex = 0.5, pch = 19); +#' +NULL + + +#' @title Mixed Shapes Clusters +#' +#' @description Matrix of 2-dimensional points that form circular and elliptical +#' patterns. +#' +#' @name mixShapes +#' +#' @docType data +#' +#' @keywords datasets +#' +#' @examples +#' data(mixShapes) +#' plot(mixShapes, cex = 0.5, pch = 19); +#' +NULL + + +#' @title T-Shaped Clusters +#' +#' @description Matrix of 2-dimensional points that form the letter T. +#' +#' @name Tset +#' +#' @docType data +#' +#' @keywords datasets +#' +#' @examples +#' data(Tset) +#' plot(Tset, cex = 0.5, pch = 19); +#' +NULL \ No newline at end of file diff --git a/man/CEC-package.Rd b/man/CEC-package.Rd index 1377892..5777ef4 100644 --- a/man/CEC-package.Rd +++ b/man/CEC-package.Rd @@ -2,6 +2,7 @@ % Please edit documentation in R/CEC-package.R \docType{package} \name{CEC-package} +\alias{CEC} \alias{CEC-package} \title{Cross-Entropy Clustering} \description{ @@ -18,6 +19,7 @@ CEC divides data into Gaussian type clusters. The implementation Konrad Kamieniecki } \keyword{cluster} +\keyword{internal} \keyword{models} \keyword{multivariate} \keyword{package} diff --git a/man/Tset.Rd b/man/Tset.Rd index 4d095d0..7dadd61 100644 --- a/man/Tset.Rd +++ b/man/Tset.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/CEC-package.R +% Please edit documentation in R/utils.R \docType{data} \name{Tset} \alias{Tset} diff --git a/man/cec.Rd b/man/cec.Rd index 3da7ba3..2c7b1f1 100644 --- a/man/cec.Rd +++ b/man/cec.Rd @@ -47,8 +47,8 @@ must not contain \code{NA} values.} Possible values are: "covariance", "fixedr", "spherical", "diagonal", "eigenvalues", "all" (default). - Currently, if the \code{centers} argument is a vector, only a single type can - be used.} + Currently, if the \code{centers} argument is a vector, only a single type + can be used.} \item{iter.max}{The maximum number of iterations of the clustering algorithm.} @@ -83,8 +83,8 @@ with a percent sign (e.g. "5\%").} visible in the results as NA in the "centers" matrix (as well as the corresponding values in the list of covariances).} -\item{interactive}{If \code{TRUE}, the result of clustering will be plotted after -every iteration.} +\item{interactive}{If \code{TRUE}, the result of clustering will be plotted +after every iteration.} \item{threads}{The number of threads to use or "auto" to use the default number of threads (usually the number of available processing units/cores) diff --git a/man/fourGaussians.Rd b/man/fourGaussians.Rd index 308a6d0..8adb6df 100644 --- a/man/fourGaussians.Rd +++ b/man/fourGaussians.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/CEC-package.R +% Please edit documentation in R/utils.R \docType{data} \name{fourGaussians} \alias{fourGaussians} diff --git a/man/mixShapes.Rd b/man/mixShapes.Rd index 8273d48..207dc5d 100644 --- a/man/mixShapes.Rd +++ b/man/mixShapes.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/CEC-package.R +% Please edit documentation in R/utils.R \docType{data} \name{mixShapes} \alias{mixShapes} diff --git a/man/threeGaussians.Rd b/man/threeGaussians.Rd index e85ceee..2607fbd 100644 --- a/man/threeGaussians.Rd +++ b/man/threeGaussians.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/CEC-package.R +% Please edit documentation in R/utils.R \docType{data} \name{threeGaussians} \alias{threeGaussians} diff --git a/src/cec_r.cpp b/src/cec_r.cpp index 9fb8e1f..5a7cf8d 100644 --- a/src/cec_r.cpp +++ b/src/cec_r.cpp @@ -62,7 +62,7 @@ SEXP cec_r(SEXP x_r, SEXP centers_param_r, SEXP control_param_r, SEXP models_par } if (ex_what) - error("%s", ex_what); + Rf_error("%s", ex_what); try { SEXP r_res; @@ -72,7 +72,7 @@ SEXP cec_r(SEXP x_r, SEXP centers_param_r, SEXP control_param_r, SEXP models_par } catch (std::exception &ex) { ex_what = ex.what(); } - error("%s", ex_what); + Rf_error("%s", ex_what); } extern "C" @@ -120,7 +120,7 @@ SEXP cec_split_r(SEXP x_r, SEXP centers_param_r, SEXP control_param_r, SEXP mode } if (ex_what) - error("%s", ex_what); + Rf_error("%s", ex_what); try { SEXP r_res; @@ -130,7 +130,7 @@ SEXP cec_split_r(SEXP x_r, SEXP centers_param_r, SEXP control_param_r, SEXP mode } catch (std::exception &ex) { ex_what = ex.what(); } - error("%s", ex_what); + Rf_error("%s", ex_what); } extern "C" @@ -157,14 +157,14 @@ SEXP cec_init_centers_r(SEXP x_r, SEXP k_r, SEXP method_r) { } if (ex_what) - error("%s", ex_what); + Rf_error("%s", ex_what); try { SEXP r_res = put(*res); return r_res; } catch (exception &ex) { ex_what = ex.what(); - error("%s", ex_what); + Rf_error("%s", ex_what); } } diff --git a/src/cov.h b/src/cov.h index 525afdd..2b1db7e 100644 --- a/src/cov.h +++ b/src/cov.h @@ -1,7 +1,7 @@ #ifndef CEC_COV_H #define CEC_COV_H -#include "vec.h" +#include "vec.h" namespace cec { diff --git a/src/r_result.cpp b/src/r_result.cpp index 9cb3b4c..60a6c19 100644 --- a/src/r_result.cpp +++ b/src/r_result.cpp @@ -17,7 +17,7 @@ SEXP cec::create_R_result(const clustering_results &out) { PROTECT(energy_vector = put(out.energy)); PROTECT(clusters_number_vector = put(out.cluster_number)); PROTECT(assignment_vector = put(out.assignment)); - PROTECT(covariance_list = allocVector(VECSXP, k)); + PROTECT(covariance_list = Rf_allocVector(VECSXP, k)); PROTECT(iterations = put(out.iterations)); PROTECT(centers_matrix = put(out.centers)); @@ -32,26 +32,26 @@ SEXP cec::create_R_result(const clustering_results &out) { } SEXP ret; - PROTECT(ret = allocList(6)); + PROTECT(ret = Rf_allocList(6)); SEXP ret_s = ret; SETCAR(ret, assignment_vector); - SET_TAG(ret, install("cluster")); + SET_TAG(ret, Rf_install("cluster")); ret = CDR(ret); SETCAR(ret, centers_matrix); - SET_TAG(ret, install("centers")); + SET_TAG(ret, Rf_install("centers")); ret = CDR(ret); SETCAR(ret, energy_vector); - SET_TAG(ret, install("energy")); + SET_TAG(ret, Rf_install("energy")); ret = CDR(ret); SETCAR(ret, clusters_number_vector); - SET_TAG(ret, install("nclusters")); + SET_TAG(ret, Rf_install("nclusters")); ret = CDR(ret); SETCAR(ret, covariance_list); - SET_TAG(ret, install("covariances")); + SET_TAG(ret, Rf_install("covariances")); ret = CDR(ret); SETCAR(ret, iterations); - SET_TAG(ret, install("iterations")); + SET_TAG(ret, Rf_install("iterations")); UNPROTECT(k + 7); return ret_s; diff --git a/src/r_utils.h b/src/r_utils.h index eef4499..d399d6d 100644 --- a/src/r_utils.h +++ b/src/r_utils.h @@ -16,7 +16,7 @@ namespace cec { template<> inline const char* get(SEXP sexp) { - if (!isString(sexp)) + if (!Rf_isString(sexp)) throw invalid_parameter_type("string vector"); return CHAR(STRING_ELT(sexp, 0)); } @@ -37,7 +37,7 @@ namespace cec { template<> inline r_ext_ptr get(SEXP sexp) { - if (!isMatrix(sexp)) + if (!Rf_isMatrix(sexp)) throw invalid_parameter_type("matrix"); int m = Rf_nrows(sexp); int n = Rf_ncols(sexp); @@ -71,7 +71,7 @@ namespace cec { SEXP r_ma; - PROTECT(r_ma = allocMatrix(REALSXP, m, n)); + PROTECT(r_ma = Rf_allocMatrix(REALSXP, m, n)); double *r_data = REAL(r_ma); for (int i = 0; i < m; i++) @@ -85,7 +85,7 @@ namespace cec { inline SEXP put(int val) { SEXP ve; - PROTECT(ve = allocVector(INTSXP, 1)); + PROTECT(ve = Rf_allocVector(INTSXP, 1)); INTEGER(ve)[0] = val; UNPROTECT(1); @@ -94,7 +94,7 @@ namespace cec { inline SEXP put(double val) { SEXP ve; - PROTECT(ve = allocVector(REALSXP, 1)); + PROTECT(ve = Rf_allocVector(REALSXP, 1)); REAL(ve)[0] = val; UNPROTECT(1); @@ -103,7 +103,7 @@ namespace cec { inline SEXP put(vector val) { SEXP ve; - PROTECT(ve = allocVector(INTSXP, val.size())); + PROTECT(ve = Rf_allocVector(INTSXP, val.size())); std::copy(val.begin(), val.end(), INTEGER(ve)); UNPROTECT(1); @@ -137,14 +137,14 @@ namespace cec { SEXP get_named(SEXP list, const char *name) { SEXP elementNames = GET_NAMES(list); - if (!isString(elementNames)) + if (!Rf_isString(elementNames)) throw invalid_parameter_type("named elements"); int len = LENGTH(elementNames); for (int i = 0; i < len; i++) { if (strcmp(name, CHAR(STRING_ELT(elementNames, i)))) continue; SEXP res = VECTOR_ELT(list, i); - if (!res || isNull(res)) + if (!res || Rf_isNull(res)) break; return res; }