-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
add set_variables alias of variables<- #296
Conversation
Thank you! Would you mind moving the code to the R file where variables() <- is defined to keep them together? Same with the tests. |
``
Done! |
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.
Thank you! I have a few minor comments before merging this.
R/draws-index.R
Outdated
#' x <- as_draws(matrix(rnorm(100), ncol = 2)) | ||
#' variables(x) | ||
#' | ||
#' x |> set_variables(c("theta[1]", "theta[2]")) |> variables() |
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.
Please avoid the use of the pipe in the docs because this may lead to a failur in old R versions not having the pipe.
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.
Fixed
R/draws-index.R
Outdated
#' variables(x) | ||
#' | ||
#' @export | ||
set_variables <- function(.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.
why use .x as the first argument here? Wouldn't x be okay too?
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.
Fixed by changing variable to x
R/draws-index.R
Outdated
|
||
#' @rdname set_variables | ||
#' @export | ||
set_variables.draws <- function(x, variables, ...) { |
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.
Why make set_variables
generic? If it is a non-generic function that just forwards to variables<-
then implementers of other classes need only override the generic there.
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 didn't think too much about this either way, as I just used rename_variables
as a template, which is a generic with only a rename_variables.draws
method defined. If it's better to change it to a non-generic function, I 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.
I defer to @paul-buerkner, but IMO it would be simpler :).
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.
Good point. didn't think of this, but I agree. We should make it a non-generic function. Same with rename_variables I think but I will look at the latter separately.
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.
non-generic sounds good to me too
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 changed it to non-generic now
Codecov Report
@@ Coverage Diff @@
## master #296 +/- ##
==========================================
+ Coverage 95.84% 95.96% +0.11%
==========================================
Files 44 44
Lines 3347 3417 +70
==========================================
+ Hits 3208 3279 +71
+ Misses 139 138 -1
📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
This is how benchmark results would change (along with a 95% confidence interval in relative change) if 72b4048 is merged into master:
|
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.
looks good. One minor thing before I will merge
R/draws-index.R
Outdated
#' x <- as_draws(matrix(rnorm(100), ncol = 2)) | ||
#' variables(x) | ||
#' | ||
#' set_variables(x, c("theta[1]", "theta[2]")) |
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 are not assigning to x here. Is that intentional?
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.
Good catch! Fixed this now.
This is how benchmark results would change (along with a 95% confidence interval in relative change) if e4af9b4 is merged into master:
|
Thank you for adding this! |
Thanks for the review! |
Summary
Adds
set_variables
function which is an alias ofvariables<-
. Fixes #281Example functionality:
Copyright and Licensing
By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the following licenses: