-
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
Add ability to modify record options #5
Conversation
@kyleam Just as a heads up... I know we can access table columns via BackgroundEdit: here is what I was thinking. I personally like retaining the functionality of allowing modifications (not just adding). This is inline with what @seth127 and I discussed as well, though I do see your point about it being unnecessary/the intent of the package. If we are ok with this functionality, I implemented the following for updating table columns (not committed). FWIW (mostly for Seth), table columns are stored as a single string (all concatenated), so they have to be updated differently from the others. To clarify: > record$values[[3]]$name
[1] "list1"
> record$values[[3]]$name_raw
NULL
> record$values[[3]]$value
[1] "ID TIME PRED RES WRES CPRED CWRES EPRED ERES EWRES" ImplementationOriginal record> record
$TABLE ID TIME PRED RES WRES CPRED CWRES EPRED ERES EWRES NOAPPEND
ONEHEADER FILE=example1.TAB NOPRINT Modifications# modify positional option
modify_record_opt(record, name = "PRED2", value = TRUE)
> record
$TABLE ID TIME PRED RES WRES CPRED CWRES EPRED ERES EWRES PRED2 NOAPPEND
ONEHEADER FILE=example1.TAB NOPRINT
# This looks similar to how we modify flags:
modify_record_opt(record, name = "NOPRINT", value = FALSE)
> record
$TABLE ID TIME PRED RES WRES CPRED CWRES EPRED ERES EWRES PRED2 NOAPPEND
ONEHEADER FILE=example1.TAB I see an issue with this. Mainly, that it treats positional options similar to flags (looks like the value is logical when in reality it's actually the character string of If we're adamant about this function only having the ability to add options, this is a moot point. Anyways, mainly wanted the three of us to be on the same page with what the function should handle. The above discussion is only worth having if we're considering opening the function up to allowing modifications as well. |
Interesting. Part 1: add/modify/removeOff the top, I feel pretty strongly that any helper we should be able to add, modify, or remove the relevant options. I could potentially see these being different functions (e.g. Part 2: just make them pass the whole string?Focusing back on this specific case (the columns in the table record), I may not be understanding this quite right, but if the issue is just that all columns are specified/parsed as a single option... what if we just make the users do that too? So the interface would be kind of like: modify_record_opt(record, "columns", vector_of_column_names) My thinking:
Does that make sense or am I totally missing some of the nuance? Part 3: separate helpers per optMy other thought is, this is part of why I was thinking about implementing specific helpers for each type of record. For example, something like this design: #' private
modify_opt_basic_impl <- function(...) {
# does the modification for all records that work for the basic case
# i.e. $DATA, $ESTIMATION, etc.
}
#' @export
modify_estimation_opt <- function(...) {
# check the the passed record is "estimation" type
modify_opt_basic_impl(...)
}
#' @export
modify_data_opt <- function(...) {
# check the the passed record is "data" type
modify_opt_basic_impl(...)
} Then That said... I'm trying to stub out that interface and having a hard time envisioning it. So maybe that's a sign that's it a bad idea. |
[ This is jumping into discussion of how to handle table
As you mention, nmrec does not parse within nmrec provides the user a way to get that string, handling a lot of the complication, but, at least with what's currently supported, everything else is left to them. That's going to be the case with a lot of record details. |
I think this helper should focus on options defined via The interface could then be
Implementation details:
|
Responding to @kyleam 's comments...
I think this is essentially the same as I was proposing in "Part 2" of my comment above, right?
This comment all makes sense to me. @barrettk read through that a few times and see if you have any outstanding questions. I think that Another comment for future direction...
That definitely makes sense to me. To be clear though, the intention is likely to parse (at least some of) those |
Yes. (Sorry for not making that clear; my reply was meant as a direct response to @barrettk's question.)
If we need them (and definitely if we need to set them), I think we should parse them. But, as with records themselves, there are lots of stuff that we don't parse, and I don't think nmrec should state that its goal is to eventually support everything (edit: by that I mean, parsing everything down to the level that every possible user would possibly want). If we do add support for parsing within table list values, I agree that it makes sense to revisit the setter, though I don't think we necessarily need to add one. If we do add this setter functionality, my current view is that we shouldn't tack that onto this setter as it would complicate the interface and implementation of the common case of "standard" options, but we can of course cross that bridge when/if we get to it. |
Based on the later suggestions, Im wondering if the code I committed on Friday could be worth a more broad review.
Implementation details:
This is done, but it didnt seem worth making a shared helper, given how little of it I used (plus I modified it).
This is done, though I still have to remove the
Hooked up
Hooked up
Gets appended to the end, but not as a new line. Easy change if that's what we want.
That's how it currently works
Will do this and add documentation. @seth127 If we proceed with columns not being able to be adjusted using this function, I dont think it makes sense to be able to use a vector of options. A) for clarity (treat it as similar to |
@kyleam I just had a conversation with @barrettk . He is going to push a few things to streamline this helper and, I'm pretty sure, coalesce to what you outline here. A few notes:
|
Yes, I agree that there should not be a type argument (as I proposed above, I'd like this to be You can know the type for sure via the |
Okay, though I think it's worth stepping back and assessing actual use cases we have.
Okay. @barrettk Let me know when it's ready to take an initial look. (I'll likely meet with you to clean up the history and tweak other minor things, but we can leave that until the main code changes from the reviews settle.) |
@kyleam just marked you to review. The one thing I didn't implement yet was the returning of In terms of the new helper function - I brought up to @seth127 that the only reason I could see for adding it, is if ctl <- parse_ctl(get("bayes1", envir = nmrec_examples))
recs <- select_records(ctl, "table")
rec <- recs[[1]]
starting_cols <- get_record_option(rec, "list1")$format()
> starting_cols
[1] "ID TIME PRED RES WRES CPRED CWRES EPRED ERES EWRES"
set_record_option(rec, name = "list1", value = paste(starting_cols, "PRED2"))
> rec
$TABLE ID TIME PRED RES WRES CPRED CWRES EPRED ERES EWRES PRED2 NOAPPEND
ONEHEADER FILE=example1.TAB NOPRINT
As an aside, I imagine we will want some |
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.
Thanks @barrettk. Here's my initial round of comments. (I didn't look too closely at the tests yet, but noticed you did a nice job of covering the different cases.)
- allows for modification of flag/value option presence - allows for adding a new option
4138d11
to
e67cc6e
Compare
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.
@barrettk Thanks for all the work on this.
Most of my later review happened on live sessions, but, making one final pass, this looks great to me.
) | ||
}) | ||
|
||
test_that("set_record_option() works with special characters and formats correctly", { |
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.
Thanks for thinking through so many cases. Looks great.
opt_end <- purrr::detect_index(record$values, function(x) { | ||
inherits(x, "nmrec_option") | ||
}, .dir = "backward") | ||
record$values <- append(record$values, new_opt_lst, after = opt_end) |
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 like this approach.
It could do some extra clean up to avoid extra spaces when removing an option, but I don't think it's worth the effort.
Great stuff all around. Thanks y'all. |
@kyleam @barrettk it seems like this is loitering and it may be that we all think we're waiting on someone else... is that right? Either way, my questions at this point are:
|
I've approved it. From my POV, it's ready to merge. For the release: if it'd be helpful for a particular case (pretty much if @barrettk would like it for work in bbr), sure. If he doesn't expect to use it immediately or is fine installing from the repo, we can also wait and see what else we get to soon (in particular, the higher-level parameter helpers). |
@kyleam @seth127 If we dont foresee any notable feature additions in the near future, I would say a release would be preferable just so we can actually merge the test-threads PR once this is hooked up (i.e. adding nmrec to pkgr and as a dependency in the Description file). If there are upcoming features within the next week or two, im fine to wait. |
The release can be made quickly, and the final changes to get it hooked up are trivial (assuming we're okay with bbr not having a dependency on MPN). So, let's wait a bit to give a little runway for other things. The minute you're nearing a "ready to review" state with test threads, let me know, I'll prepare the release pr for you to approve. |
That all sounds good to me.
That was the only other thing I had in mind too, but we can see how things shake out over the next couple weeks. Thanks both. |
FYI - I just added this issue in bbr related to this. We can talk about which of those we think it's worth tackling in the near future. I know |
$EST
,$TABLE
, and$DATA
records for now