From f91395a859a3d52236b3797992683f8b9d52f1be Mon Sep 17 00:00:00 2001 From: "Watal M. Iwasaki" Date: Mon, 10 Jun 2024 17:20:48 +0900 Subject: [PATCH] Skip set.seed() if NA_integer_ is given. This should address #52 but currently it does not work because `NA_integer_` is implemented as the maximum negative value, and a negative seed causes an error "negative length vectors are not allowed". `base::set.seed()` accepts negative seeds without any problem, which indicates ClusterR is doing something wrong with negative seeds. --- inst/include/ClusterRHeader.h | 1 + inst/include/affinity_propagation.h | 1 + 2 files changed, 2 insertions(+) diff --git a/inst/include/ClusterRHeader.h b/inst/include/ClusterRHeader.h index 9761f20..54059b2 100644 --- a/inst/include/ClusterRHeader.h +++ b/inst/include/ClusterRHeader.h @@ -117,6 +117,7 @@ namespace clustR { void set_seed(int seed) { + if (Rcpp::all(Rcpp::is_na(Rcpp::IntegerVector(seed)))) return; Rcpp::Environment base_env("package:base"); Rcpp::Function set_seed_r = base_env["set.seed"]; set_seed_r(seed); diff --git a/inst/include/affinity_propagation.h b/inst/include/affinity_propagation.h index 9564ab6..344ce2a 100644 --- a/inst/include/affinity_propagation.h +++ b/inst/include/affinity_propagation.h @@ -58,6 +58,7 @@ class Affinity_Propagation { //--------------------------------------------------------------------------------- void Affinity_Propagation::set_seed(int seed) { + if (Rcpp::all(Rcpp::is_na(Rcpp::IntegerVector(seed)))) return; Rcpp::Environment base_env("package:base"); Rcpp::Function set_seed_r = base_env["set.seed"]; set_seed_r(seed);