taiyun / corrplot

A visual exploratory tool on correlation matrix
https://github.com/taiyun/corrplot
Other
318 stars 87 forks source link

Some functions wrongly marked as pure #232

Closed vsimko closed 3 years ago

vsimko commented 3 years ago

https://github.com/taiyun/corrplot/blob/430e501c71f09d8100358d8053b52bfaec004996/R/corrplot.R#L1047-L1067

If these functions are drawing something, this means they cannot be pure because they have a side effect.

taiyun commented 3 years ago

What is pure function?

vsimko commented 3 years ago

Well, a pure function is such a function which does not have any side effects and for any input it always returns the same output. For example, a mathematical function such as f(x) = x^2 is pure. However, function f(x) = sample(1:10, x) isn't pure because it returns different random values for the same input. Also a function f(x) = print(x) isn't pure because it causes a side effect (printing to console).

Pure functions behave nicely, they can be easily tested and reason about.