Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

odd behaviour when colouring based on a numeric vector #24

Closed
tim-salabim opened this issue Sep 28, 2018 · 3 comments
Closed

odd behaviour when colouring based on a numeric vector #24

tim-salabim opened this issue Sep 28, 2018 · 3 comments
Labels
bug Something isn't working
Milestone

Comments

@tim-salabim
Copy link

I encountered some rather odd behaviour when using colur_values_rgb on a numeric vector. The vector gets modified by reference, see below.

# integer works as expected
set.seed(23)
v = sample.int(100, 10)
v
# [1] 58 23 33 69 79 41 91 94 78 93
clrs = colour_values_rgb(v, include_alpha = FALSE) / 255
v
# [1] 58 23 33 69 79 41 91 94 78 93

# numeric gets mumbled
set.seed(23)
v = as.numeric(sample.int(100, 10))
v
# [1] 58 23 33 69 79 41 91 94 78 93
clrs = colour_values_rgb(v, include_alpha = FALSE) / 255
v
# [1] 0.4929577 0.0000000 0.1408451 0.6478873 0.7887324 0.2535211 0.9577465 1.0000000 0.7746479 0.9859155

Any ideas?
The colours are identical, btw.

@SymbolixAU
Copy link
Collaborator

Yes, that's unexpected. The numeric v is returned scaled [0,1] , so I might need to put a clone() in there somewhere.

But that doesn't explain why the integer works though.

I'll investigate tomorrow

@SymbolixAU
Copy link
Collaborator

Ok, a bit of digging,

All my Rcpp method signatures for "numbers" are Rcpp::NumericVector. So, when passing in an integer vector (from R), it has to be coerced to a NumericVector, thus a copy is made, and hence the difference between the integer and numeric results.

References:

Fix is incoming

SymbolixAU pushed a commit that referenced this issue Sep 29, 2018
@SymbolixAU SymbolixAU self-assigned this Sep 29, 2018
@SymbolixAU SymbolixAU added this to the v0.1.0 milestone Sep 29, 2018
@SymbolixAU SymbolixAU added the bug Something isn't working label Sep 29, 2018
@tim-salabim
Copy link
Author

Thanks! Just tested and behaves as expected now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant