Skip to content

Always display NA as unquoted in the Variables pane #432

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

Merged
merged 7 commits into from
Jul 15, 2024

Conversation

yutannihilation
Copy link
Contributor

This pull request addresses posit-dev/positron#3810

Since format() and format_one() belongs to Vector, I think format_with_string_options() should also belong to Vector and be called there. But, I'm not sure if it's a good idea to include FormattedVectorCharacterOptions in the signature of all types of Vector. Considering posit-dev/positron#2860 will introduce a facility to handle this kind of distinction easier, I'm not sure if this is worth, but I share this code just in case this helps.

Copy link
Contributor

@lionel- lionel- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind having it in the signature, the added verbosity has the advantage that callers get reminded of formatting options. @dfalbel Since you worked on formatting, could you review this PR please?

@yutannihilation
Copy link
Contributor Author

Thanks, then I mark this as ready.

One note is that I'm wondering if Vector might be better to have an associated type of Options instead of using FormattedVectorCharacterOptions for all types of vectors (e.g. a numeric vector needs an option for the number of digits?). At the moment, I don't see the necessity for it, but we might revisit here in future.

@yutannihilation yutannihilation marked this pull request as ready for review July 10, 2024 09:26
Copy link
Contributor

@dfalbel dfalbel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These options were introduced in order to be able to control the formatting for the data explorer (#344), but we no longer use the FormattedVector interface (see #382) because this interface wasn't flexible enough to support both use cases. AFAICT FormattedVector is currently only used by the Variables pane, so we can make it specific for it.

Another approach could be to simply remove those and we can add it back if we need it at some point.

We should also add a test for the NA formatting here to make sure we don't regress on it:

fn format_elt_unchecked(
&self,
index: isize,
options: Option<&FormattedVectorCharacterOptions>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should move the definition of FormattedVectorCharacterOptions into this file.
We probably also want to change it's name to something like FormatOptions as it's no longer specific to character vectors.

None => String::from("NA"),
}
}

fn format_with_string_options(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be renamed to format_with_options.

@yutannihilation
Copy link
Contributor Author

Thanks for the review! Renamed the struct and add a test.

Also, thanks for the context. So, maybe it needs some more cleanup? I want to keep this pull request small for now (mainly because I don't know well about the implementations), but I can address in a separate pull request.

Copy link
Contributor

@dfalbel dfalbel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @yutannihilation for the PR! I have just added a few more comments, but this looks great!

None => String::from("NA"),
}
}

fn format_with_options(&self, value: String, options: &FormatOptions) -> String {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this only affects the character vectors, this should be moved to the character_vector.rs file.

// Formatting options for character vectors
pub struct FormatOptions {
// Wether to quote the strings or not (defaults to `true`)
// If `true`, elements will be quoted during format so, eg: c("a", "b") becomes ("\"a\"", "\"b\"") in Rust
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should document that the quote option only affects character vectors.

@yutannihilation
Copy link
Contributor Author

Thanks! I inlined format_with_options() and added a note.

@dfalbel dfalbel merged commit 7e16d1a into posit-dev:main Jul 15, 2024
3 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jul 15, 2024
@yutannihilation yutannihilation deleted the format-na branch July 15, 2024 22:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants