-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
forced join - qenv #85
Conversation
* constructor, eval_code, lockEnvironment - need validation * prototype * constructor for the list of data (possibly reactive) * progress with join quosure * - added more constructors - test constructors - test join * update WIP * fix constructor from list * Update Quosure.R * add id to the code, resolve join conflicts, more test * implement id field in Quosure to distinguish detect code entries
This reverts commit cc3db0c.
Signed-off-by: Nikolas Burkoff <nikolas.burkoff@roche.com>
Signed-off-by: Nikolas Burkoff <nikolas.burkoff@roche.com>
@@ -9,6 +9,11 @@ | |||
#' - more cases to be done | |||
#' @param x (`qenv`) | |||
#' @param y (`qenv`) | |||
#' @param force (`logical(1)`) whether to turn off automatic validation and duplicated code removal, by default `FALSE`. |
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.
What do you think about explaining objects in y
overwrite those in x
?
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.
agreed
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 few comments from me.
Also note - I can't see this functionality being used - we haven't needed it in our codebase - but I guess there's no harm if it's there for others
standardGeneric("join") | ||
}) | ||
|
||
#' @rdname join | ||
#' @export | ||
setMethod("join", signature = c("qenv", "qenv"), function(x, y) { | ||
setMethod("join", signature = c("qenv", "qenv"), function(x, y, force, verbose) { |
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.
could force and verbose have default args and then just a simple checkmate::assert_flag() - or does S4 not allow 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.
+1 for default values,.
Furthermore I suggest force = TRUE, value = force
.
S4 does allow this. If I'm not mistaken, if assertions are put in a method with signature = "ANY"
that does not call callNextMethod()
, they will be applied to all methods with more specific signature
s.
if (verbose) { | ||
message("The join method of qenv was forced, please be careful and manually validate the results.") | ||
if (isTRUE(join_validation)) { | ||
warning("Forced join is not recomended for this scenario, the default mechanism seems to be suited.") |
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.
So I don't like the fact that join(x, y, force = TRUE) and join(x, y, force = FALSE) give different answers if check joinable is true (and both qenv's have some shared code at the beginning) as that's confusing -> we could instead change it so force = TRUE only changes the behaviour if it would have given an error.
Or maybe we could use a different function like concatenate or just c
as that's what force join is effectively doing
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.
For me the default behaviour is more surprising than the forced one.
"we could instead change it so force = TRUE only changes the behaviour if it would have given an error."
My idea about force it is that it works always and at the same predicted way.
We simply join what is provided.
y@id <- c(x@id, y@id) | ||
y@code <- c(x@code, y@code) | ||
y@warnings <- c(x@warnings, y@warnings) | ||
y@messages <- c(x@messages, y@messages) | ||
|
||
# insert (and overwrite) objects from y to x | ||
y@env <- rlang::env_clone(y@env, parent = parent.env(.GlobalEnv)) | ||
rlang::env_coalesce(env = y@env, from = x@env) | ||
y |
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.
So it's correct but very confusing for this to be the other way round to the case above - I wonder if we need a few more code comments at the very least? I couldn't think of a nice way to neaten this up...
In the issue I left the comment "Make a decision if this is needed first" which makes me realize that we can undermine this need. In my opinion we can keep |
This issue is in my opinion help users as gives an option of full control which is always good. @gogonzo @nikolas-burkoff I am more concern about the |
For me
In general one couldn't modify/create the objects in @Polkas does it address your comments?
|
COmments and idea for improvements:
|
Signed-off-by: Nikolas Burkoff <nikolas.burkoff@tessella.com>
Signed-off-by: Nikolas Burkoff <nikolas.burkoff@tessella.com>
Signed-off-by: Nikolas Burkoff <nikolas.burkoff@tessella.com>
Signed-off-by: Nikolas Burkoff <nikolas.burkoff@tessella.com>
Stuff highlighted in your comment was discussed here. This is neat solution but causes problems. Please consider the scenario step by step
so the a1 and a2 has been lost here.
So the problem is that only last environment is moved, and we should move all upstream environments up to the point where they have the same parent. If anyone has a better solution I'd be glad.
Yes, I'm open for suggestions. Your concern is similar to the previous there - let's continue discussion there |
My view would be to close this and not worry about force joining until we or a module developer explicitly needs this functionality. I quite like the idea of forcing people to keep the contents of qenv's as simple as possible especially as there are plenty of edge cases where things won't work as expected |
I second this opinion regarding this PR. |
I agree on this statement. |
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.
So this is not an implementation of force join - it is a concatenation. If we want a concatenate behaviour then that is not a problem but I would recommend naming the function something different.
It is very confusing and non-standard to have different behaviour when force = TRUE and force = FALSE when both cases work.
A force join would carry out the same action as a normal join but not bothering with the checks about whether it's joinable and just assuming it is. We haven't found a need for it in our code base so I wouldn't implement it but I guess you could use it for the edge case below as I the developer know that although the check_joinable checks fail - joining is (assuming i
is not used later without being assigned) an OK option
And when you force join the qenv the code should be:
x <- 4
a <- numeric(0); for(i in 1:2) a <- c(a, i)
b <- numeric(0); for(i in 1:3) b <- c(b, i)
and not the concatenation of the qenv which would give:
x <- 4
b <- numeric(0); for(i in 1:3) b <- c(b, i)
x <- 4
a <- numeric(0); for(i in 1:2) a <- c(a, i)
@nikolas-burkoff thank you for your insight even that we know that we will not introduce this functionality. @nikolas-burkoff I could add to your example a simpler case that somebody want to have a duplicated code:) |
closes #56
Add the force argument to add the optional full control around the join method.
The force name is inspired from bash and git where the unsecure options have to be forced.
The forced join is always attached with advice message and optional warning if the default join seems to be suited.
The warning and message could be turn off.