-
Notifications
You must be signed in to change notification settings - Fork 0
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
overhaul with new approach #21
base: main
Are you sure you want to change the base?
Conversation
I can deal with the linting issues, but not sure about the test-coverage - my end, the tests work (though they did some troubleshooting). |
Nice! Will take a look tonight. This is the error. Is the test CI missing a dependency? |
Not sure how that gets specified - the DESCRIPTION and NAMESPACE dependencies correctly connect to digest. Whereabouts do CI package dependencies live? Presumably somewhere in the YAML configs. |
If they are in the DESCRIPTION it should pick them up. Platform specific issue maybe? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functionality wise this looks good. I still have big reservations about the design (i.e overwriting base functions)
formals(.FUN) <- c(formals(rFUN), alist(hash = )) | ||
dispatch <- as.character(substitute(rFUN)) | ||
hashc <- str2lang("set.hash(hash, get('.hash.salt', envir = parent.frame()))") | ||
origc <- str2lang(sprintf("%s%s%s(%s)",dispatch[2],dispatch[1],dispatch[3],toString(names(formals(rFUN))))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bunch of linting issues here
#' | ||
#' @export | ||
set.salt <- function(salt) { | ||
assign(".hash.salt", salt, envir = parent.frame()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have you thought about doing this with options? I think it might be a lot more cran compliant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little bit, but the idea is to have a scope-driven salt value - that probably means setting something in an environment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but options can do that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or an environment variable (options -> environment variable would be the classic approach I think)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this approach is an environment variable?
i don't think the options version let's you do this cleanly - unsetting the variable when leaving a scope seems messy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it is its a normal variable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I mean (though I didn't mean via this nice little wrapper package): https://cran.r-project.org/web/packages/options/vignettes/envvars.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Like the way we handle the cache location in epinowcast
: https://github.com/epinowcast/epinowcast/blob/12c24bf509704c4384902408f36dff86e73fef5b/R/model-tools.R#L635
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, i should say: it's a normal variable, in the r-environment-scoping sense. so when r does its normal search enclosing scopes to find a token, it gets found. it also gets cleaned up etc like normal, & can exist in closer scope, while outer scope has its own (masked until that scope is returned to).
export(rbinom) | ||
export(rcauchy) | ||
export(rchisq) | ||
export(rexp) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have an issue to approach not needing to do this? It seems like quite an unsafe design and one that I don't think will fly with CRAN
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm relatively confident this is actually what users want - minimal modification to their code to use this capability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great but I don't think you will be able to get it on CRAN!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤷 give the people what they want.
that said: i agree there are tradeoffs here. my goal: enable the user to switch matching on and off, without having to change code. this approach currently only makes the refactor easy-ish. so:
- make the refactor easier: provide a bit of static analysis to find invocations of the overriden functions, that don't have a
hash = ...
argument - make the switching (back to base) possible with an option / package environment variable
- be a bit noisier when loading the package
i think adding those also helps allay some of the overloading concerns. I think there's one other, harder problem to solve: making it possible to use hashprng within another package (that does some thing that requires matching) without having that leak out of that package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think as suggested elsewhere if going to do this I wouldn't do it via reexporting but instead have a overload function that users can use and then use this is an option etc to overload a list of common r functions (i.e these)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you'll still have to assign to the global environment which isn't great but at least its a bit more in line with normal practice?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, i don't recall that suggestion. makes some sense - so basically, users would do:
library(hashprng)
hashoverload() # defaults to everything hashprng knows about
... some code ...
hashunload() # turns off overloads
# or hashoverload(c("unif", "binom")) # runif and rbinom only
# or hashoverload(c("custom")) # wraps some rcustom that it finds in the environment
that's a little more onerous, but definitely less likely to annoy the CRAN gods.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still doesn't deal well with people having re-written their code to have hash = ...
arguments, that need to be ignored if they've switched off matching.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for the latter I would enforce they actually use a wrapper around their dists (that can have args the dists don't have) and then they can turn hashing on and off using an option.
It means they have to rewrite their code but they can easily the turn it on and off if they are so minded?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one aside: R CMD check passes just fine.
Yes if different to the DESCRIPTION ones |
Chucks the old approach, in with the new.