Closed ebuhle closed 4 years ago
I think this was directly related to #24 - I missed a clone
statement.
Please try the latest version from github
devtools::install_github("SymbolixAU/colourvalues")
Then you should see the expected behaviour
library(colourvalues)
set.seed(123)
x <- runif(10,-10,10)
y <- x
x
y
z <- color_values(y, palette = get_palette("cividis")[256:1, ] )
x
y
z
Note also that colourvalues
has a get_palette()
function for getting various palettes.
Thanks very much, @SymbolixAU. The GitHub version does indeed resolve the issue. I gather the clone
statement is on the C++ side, so I'll shield my eyes and pretend I never saw this. :-)
And thanks for the tip about get_palette()
; I knew there were various options but I wasn't clever enough to figure out how to reverse the direction.
yeah it's a C++ thing :)
Issue description
Satisfied colourvalues user here, but encountering some very strange behavior after updating R (session info below). When
color_values()
is called, it modifies not only the object passed as thex
argument, but also other object(s) that are copies ofx
.This seems related to #24, but that issue focused on the difference between integer and numeric arguments. My question is rather how the function could be modifying the object in the global environment that is passed to it. This is very unexpected behavior in R, and even more surprising is that copies of that object are modified. This breaks everything I thought I knew about R.
Session info
In addition to the following info for my system, a colleague has reproduced this on a Mac (don't know session info, but would assume everything up to date).
Reprex
Expected result
The objects
y
and, certainly,x
are not affected by callingcolor_values()
.Actual result
I've been using colourvalues for a year or so and I've never seen any strange behavior like this until now. In scripts, code that worked fine before now has this unexpected side effect. (I noticed it after updating from R 3.6.1 to 3.6.2 and updating packages, though I haven't tried rolling anything back.)