diff --git a/R/palettes.R b/R/palettes.R index 6dbd788..7cb45e1 100644 --- a/R/palettes.R +++ b/R/palettes.R @@ -11,7 +11,7 @@ #' get_palette( "viridis" ) #' get_palette( "rainbow" ) #' -#' @return 256 row x 3 column matrix if \code{rgb = TRUE}, otherwise a 256-length vector. +#' @return 3 column matrix if \code{rgb = TRUE}, otherwise a 256-length vector. #' #' @export get_palette <- function( palette, rgb = TRUE ) { diff --git a/inst/include/colourvalues/palette_utils/palette_utils.hpp b/inst/include/colourvalues/palette_utils/palette_utils.hpp index d9b18b5..d29ab30 100644 --- a/inst/include/colourvalues/palette_utils/palette_utils.hpp +++ b/inst/include/colourvalues/palette_utils/palette_utils.hpp @@ -69,7 +69,8 @@ namespace palette_utils { std::string& palette, Rcpp::NumericVector& red, Rcpp::NumericVector& green, - Rcpp::NumericVector& blue ) { + Rcpp::NumericVector& blue + ) { if( palette == "viridis" ) { red = colourvalues::palette::viridis_red; diff --git a/man/get_palette.Rd b/man/get_palette.Rd index 4f91f59..5f36052 100644 --- a/man/get_palette.Rd +++ b/man/get_palette.Rd @@ -13,7 +13,7 @@ get_palette(palette, rgb = TRUE) \code{TRUE}, or a vector of hex strings \code{FALSE}} } \value{ -256 row x 3 column matrix if \code{rgb = TRUE}, otherwise a 256-length vector. +3 column matrix if \code{rgb = TRUE}, otherwise a 256-length vector. } \description{ retrieves one of the available palettes diff --git a/src/palettes.cpp b/src/palettes.cpp index 0e3fc4c..7f3c085 100644 --- a/src/palettes.cpp +++ b/src/palettes.cpp @@ -5,12 +5,14 @@ using namespace Rcpp; // [[Rcpp::export]] Rcpp::NumericMatrix rcpp_get_palette( std::string palette ) { - int n = 256; - Rcpp::NumericVector red( 255.0, n ); - Rcpp::NumericVector green( 255.0, n ); - Rcpp::NumericVector blue( 255.0, n ); + + Rcpp::NumericVector red; + Rcpp::NumericVector green; + Rcpp::NumericVector blue; colourvalues::palette_utils::resolve_palette( palette, red, green, blue ); + R_xlen_t n = red.length(); + Rcpp::NumericMatrix nm( n, 3 ); nm( Rcpp::_, 0 ) = red * 255; nm( Rcpp::_, 1 ) = green * 255; diff --git a/tests/testthat/test-palettes.R b/tests/testthat/test-palettes.R index 550b03a..b9024cf 100644 --- a/tests/testthat/test-palettes.R +++ b/tests/testthat/test-palettes.R @@ -8,10 +8,9 @@ test_that("palettes are returned", { expect_true( length(all_palettes) == 52 ) for( palette in all_palettes ) { - print(palette) expect_silent( colour_values(1, palette = palette )) res <- colourvalues::get_palette( palette ) - expect_true( ncol( res ) == 3 & nrow( res ) == 256 ) + expect_true( ncol( res ) == 3 ) ## And call the function directly res <- eval(parse(text = paste0("colourvalues:::", palette, "()")))