Skip to content

Commit

Permalink
fix for #24
Browse files Browse the repository at this point in the history
  • Loading branch information
SymbolixAU committed Sep 29, 2018
1 parent aafea2a commit 4ca210a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: colourvalues
Type: Package
Title: Assigns Colours to Values
Version: 0.1.0
Date: 2018-09-20
Version: 0.1.1
Date: 2018-09-29
Authors@R: c(
person("David", "Cooley", ,"[email protected]", role = c("aut", "cre"))
)
Expand Down
14 changes: 9 additions & 5 deletions src/ColourValues.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ Rcpp::StringVector rcpp_colour_num_value_string_palette_hex(
std::string na_colour,
Rcpp::NumericVector alpha,
bool include_alpha ) {
return colourvalues::colours_hex::colour_value_hex( x, palette, na_colour, alpha, include_alpha );
Rcpp::NumericVector x2 = Rcpp::clone(x);
return colourvalues::colours_hex::colour_value_hex( x2, palette, na_colour, alpha, include_alpha );
}

// [[Rcpp::export]]
Expand All @@ -24,7 +25,8 @@ Rcpp::StringVector rcpp_colour_num_value_rgb_palette_hex(
Rcpp::NumericMatrix palette,
std::string na_colour,
bool include_alpha ) {
return colourvalues::colours_hex::colour_value_hex( x, palette, na_colour, include_alpha );
Rcpp::NumericVector x2 = Rcpp::clone(x);
return colourvalues::colours_hex::colour_value_hex( x2, palette, na_colour, include_alpha );
}

// [[Rcpp::export]]
Expand All @@ -34,7 +36,7 @@ Rcpp::StringVector rcpp_colour_str_value_string_palette_hex(
std::string na_colour,
Rcpp::NumericVector alpha,
bool include_alpha ) {
return colourvalues::colours_hex::colour_value_hex( x, palette, na_colour, alpha, include_alpha );
return colourvalues::colours_hex::colour_value_hex( x, palette, na_colour, alpha, include_alpha );
}

// [[Rcpp::export]]
Expand All @@ -58,7 +60,8 @@ Rcpp::NumericMatrix rcpp_colour_num_value_string_palette_rgb(
std::string na_colour,
Rcpp::NumericVector alpha,
bool include_alpha ) {
return colourvalues::colours_rgb::colour_value_rgb( x, palette, na_colour, alpha, include_alpha );
Rcpp::NumericVector x2 = Rcpp::clone(x);
return colourvalues::colours_rgb::colour_value_rgb( x2, palette, na_colour, alpha, include_alpha );
}

// [[Rcpp::export]]
Expand All @@ -67,7 +70,8 @@ Rcpp::NumericMatrix rcpp_colour_num_value_rgb_palette_rgb(
Rcpp::NumericMatrix palette,
std::string na_colour,
bool include_alpha ) {
return colourvalues::colours_rgb::colour_value_rgb( x, palette, na_colour, include_alpha );
Rcpp::NumericVector x2 = Rcpp::clone(x);
return colourvalues::colours_rgb::colour_value_rgb( x2, palette, na_colour, include_alpha );
}

// [[Rcpp::export]]
Expand Down
27 changes: 27 additions & 0 deletions tests/testthat/test-colour_values.R
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,30 @@ test_that("alpha can be excluded from results", {

})

test_that("original vectors returned",{
## https://github.com/SymbolixAU/colourvalues/issues/24
x <- 1L:10L
y <- 1L:10L
invisible( colour_values(x) )
expect_true( all(x == y) )
invisible( colour_values_rgb(x))
expect_true( all(x == y))

set.seed(1)
x <- as.numeric( sample.int(100, 10))
set.seed(1)
y <- as.numeric( sample.int(100, 10))
expect_true( all( x == y ))
invisible( colour_values(x) )
expect_true( all( x == y ))


set.seed(1)
x <- as.numeric( sample.int(100, 10))
set.seed(1)
y <- as.numeric( sample.int(100, 10))
expect_true( all( x == y ))
invisible( colour_values_rgb(x) )
expect_true( all( x == y ))

})

0 comments on commit 4ca210a

Please sign in to comment.