-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
New helper function repair_variable_names #318
base: master
Are you sure you want to change the base?
Conversation
@@ -173,6 +175,31 @@ set_variables <- function(x, variables, ...) { | |||
return(x) | |||
} | |||
|
|||
#' @rdname set_variables | |||
#' @param old_variables (character) Variable names to repair. Should be 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.
For now I went with old_variables
as the argument name, but happy to change this based on feedback.
stop_no_call( | ||
"All names in 'old_variables' must contain at least one '.' in the name." | ||
) |
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 simplicity I added an error if all the names don't have a .
in it. It would be strange to pass in a vector like c("theta.1", "theta[2]")
so I don't think we need to write out the logic to handle mixed cases like that. But let me know if you disagree and I can add that logic.
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 logic seems very unhelpful if I have some variables which are scalars. I can no longer just pass the entire list to this function
I believe the set of transformations here is idempotent, so if someone passes theta[1]
, nothing will be changed, so why not allow it
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #318 +/- ##
=======================================
Coverage 95.60% 95.61%
=======================================
Files 47 47
Lines 3686 3694 +8
=======================================
+ Hits 3524 3532 +8
Misses 162 162 ☔ View full report in Codecov by Sentry. |
Maybe |
I like "repair". Having the dots instead of [] is kind of a thing we don't really want. So we are repairing them to look reasonable again. But I also don't have strong opinions. So completely fine by me if we call it differently. |
Re: function name: is the intention to create a function that specifically converts from Stan names, or is the intention that this function might (in the future) support other non-posterior-friendly naming conventions? I think that should influence the naming; e.g. is this "convert_from_stan_names" (though perhaps less verbose) or the more generic "repair_variable_names" or "convert_variable_names"? Or is it "repair_dotted_indices" or "repair_dotted_index_names" or something like that? |
Good point @mjskay. If this will only ever be used to convert Stan names we could include that in the function name. What do others think? |
I think it would be best to make the function specific for Stan naming conventions, and then add other functions if we add support for other packages. The name "convert_from_stan_names" would be then very descriptive, and I don't know how to make it shorter Furthermore, in #317 @WardBrian wrote
If we want to support these, too, I assume that we would like to have something like And the natural complex type support is a separate issue #319 and PR #321 |
I agree with Jonah and Aki. |
If you did want to support tuple names, this essentially just needs to split on |
closes #317
Summary
repair_variable_names
converts names using periods (theta.1.1
) to square brackets (`theta[1,1])Copyright and Licensing
By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the following licenses: