Skip to content

Custom key mangling#89

Open
wlandau wants to merge 2 commits into
richfitz:masterfrom
wlandau:88
Open

Custom key mangling#89
wlandau wants to merge 2 commits into
richfitz:masterfrom
wlandau:88

Conversation

@wlandau

@wlandau wlandau commented Nov 4, 2018

Copy link
Copy Markdown
Contributor

To follow up on #88 (comment), this PR proposes custom mangle_key_encode and mangle_key_decode functions for the RDS driver constructor. It is not quite working yet (I find it difficult to interact with test-driver.R) but does demonstrate what I am proposing.

@richfitz richfitz left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've suggested a fairly substantial change in one of the comments - would you mind having a go at that?

Comment thread R/utils.R Outdated
}
}

assert_function <- function(x, name = deparse(substitute(x))) {

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This already exists on line 53 😁

Comment thread R/driver_rds.R
##' @param default_namespace Default namespace (see
##' \code{\link{storr}}).
##'
##' @param mangle_key_encode Optional function for mangling keys.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am thinking about the interface here and I think that we should offer a single argument here; the existing mangle_key which can take string arguments

  • none - equivalent to the current FALSE
  • base64 - equivalent to the current TRUE
  • xxxx - a key for a "registered" mangler

Then we need a new function:

register_mangler <- function(name, encode, decode, overwrite = FALSE) {...}

which adds a new mangling strategy. Then drake would call as part of initialisation (.onLoad), storr::register_mangler("drake::lazy_base64", drake::lazy_base64_encode, drake::lazy_base64_decode)

We'll save the functions into the class much as you have here.

My thinking here is that storr archives need to be openable by previous and future versions of storr, and that the options should be saved into the archive itself to avoid corrupting them (there's some fairly nasty logic going on already for that).

@wlandau wlandau Nov 6, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that idea the best so far. Implementation and back compatibility are much easier this way. I will start a new branch and PR tomorrow.

Comment thread R/driver_rds.R
write_if_missing("TRUE", driver_rds_config_file(path, "compress"))
write_if_missing("md5", driver_rds_config_file(path, "hash_algorithm"))
write_if_missing(
deparse(mangle_key_encode),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One downside of this approach is that the deparse route is not going to result in something that can be parsed back out as a usable function later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants