Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
feat: added formatting function for filter panel classes #28
feat: added formatting function for filter panel classes #28
Changes from 4 commits
3020d22
e37e73c
a0ab58b
5d2986f
49ab696
0ede485
ee4f770
7e62953
8205487
967a751
02d3b9c
99999c0
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
these 5 lines can be simplified to one vapply
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.
If we care about lines, I can do it in 2 with the previous approach 🤷🏻
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.
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.
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.
It's little too much for the simple task. Handling indention etc can be done in much simpler way:
If we need nice naming you can return the list similar to
get_filter_states
but with nicer names. And at the end useyaml::as.yaml
to pretty-print this list.For example output list could be
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.
That's a neat idea and I was toying with something similar as well, although...
I feel like creating compound list names is as annoying to do as making a string. If I want to create a name for these lists I need to declare a string anyway and at this point, does it really make sense to make a list of it if I can just return the string?
Also - if I want to do it nicely, then each of these classes will need to create a list (with custom list names which is annoying to do), then cast it to yaml, then I need to capture output that yaml and then return the captured string from a method? Seems like a lot of steps can be skipped there.
Alternatively, you could just return yaml, but it sort of beats the idea of returning a human-readable (so, something clear that does not need a full API reference to understand) string from this method, which was the motivation for this task. I agree it's not there yet, but as outlined - it's wip.
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.
Yup, I agree it's a hard choice. But when I see number of function calls, concatenating, formatting, appending vectors and paste-collapse then making a list might be worth a shot - especially that PR is still missing keep_na and keep_inf informations which are going to add more code. This code is too long for relatively simple task - there are some places where we can reduce number of calls (if we use sprintf).
Altenratively, what about
yaml::as.yaml(datasets$get_filter_state(pretty = TRUE))
?I see the point of making format functions as we can fully control the output. I'm leaving the decision between list-to-yaml and recursive-format to you. I'm happy also with the
class$format
but with simpler formatting code.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 want to avoid sprintf because its support for
NULL
and zero length arrays is awful and usingpaste
makes it so much easier. Replacingpaste
withsprintf
won't really make a difference in terms of complexity, it will just move it to dealing with zero-length arrays and NULL values which is more annoying for me. As it is now, the string is built in a somewhat logical manner which is a plus for me.I am actually debating adding NA or Inf. I actually think the Inf part is inconsequential and keep NA needs to be transformed somehow to be more meaningful.
This looks like an easy task but it's annoying to do if we care about human readability and the latter is the crux of the issue.
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.
wouldn't
work as well? And in other places? Or is it a deliberate decision to use for loops
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.
They don't return a character(1) always.
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.
Plus, I usually append things to the out object (not always) before looping and apply stuff doesn't capture by reference from their lexical scopes, so I opted to use for loops everywhere. Plus, for loops in R stopped being less performant than apply stuff ages ago, so tbh there's no particularly good reason to use them except for 'list or dict comprehension'-style programming.
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.
fair enough just askin' ;)
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.
The super constructor already checks it.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.