This is used to determine if caching already corresponds to a style guide.
Code to create a cache for. This should be styled text, as the approach used by styler does not cache input, but styled code.
A list of transformer functions, because we can only know if text is already correct if we know which transformer function it should be styled with.
We need to compare:
text to style. Will be passed to hash function as is.
styler version. Not an issue because for every version of styler, we build a new cache.
transformers. Cannot easily hash them because two environments won't be
identical even if they contain the same objects (see 'Experiments'). Simple
as.character(transformers) will not consider infinitively recursive
To fix this, transformers must have names and version number as described
create_style_guide(). Now, the only way to fool the cache invalidation
is to replace a transformer with the same function body (but changing
the function definition of the functions called in that body) interactively
without changing version number of name at the same time.
There is unexplainable behavior in conjunction with hashing and environments:
except when they have the exact same parent environment, which must be an
object created and then passed to
purrr::partial(.env = ...), not
purrr::partial() seems to ignore
.env after version 0.2.5, so until
this is fixed, we'd have to work with version 0.2.5.
Our caching backend package,
R.cache:::getChecksum.default (which uses
digest::digest()) to hash the
input. The latter does not seem to care if the environments are exactly
equal (see 'Examples').
However, under some circumstances, it does: Commit 9c94c022 (if not overwritten / rebased by now) contains a reprex. Otherwise, search for 43219ixmypi in commit messages and restore this commit to reproduce the behavior.