Skip to content

Commit 415ee07

Browse files
committed
Improve comments for format_object
1 parent d5ec59b commit 415ee07

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

crates/ark/src/data_explorer/format.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ fn format_values(x: SEXP, format_options: &FormatOptions) -> anyhow::Result<Vec<
8282
}
8383

8484
fn format_object(x: SEXP) -> Vec<FormattedValue> {
85-
// we call r_format() to dispatch the format method
85+
// We call r_format() to dispatch the format method
8686
let formatted: Vec<String> = match r_format(x) {
8787
Ok(fmt) => match RObject::from(fmt).try_into() {
8888
Ok(x) => x,
@@ -91,8 +91,8 @@ fn format_object(x: SEXP) -> Vec<FormattedValue> {
9191
Err(_) => return unknown_format(x),
9292
};
9393

94-
// but we also want to show special value codes. we call base::is.na() to dispatch
95-
// the is.na() function and then replace those with FormattedValues::NA.
94+
// But we also want to show special value codes. We call `base::is.na()` to dispatch
95+
// the `is.na()` function and then replace those with `FormattedValues::NA`.
9696
let is_na = RFunction::from("is_na_checked")
9797
.add(x)
9898
.call_in(ARK_ENVS.positron_ns);
@@ -103,26 +103,26 @@ fn format_object(x: SEXP) -> Vec<FormattedValue> {
103103
.into_iter()
104104
.zip(unsafe { LogicalVector::new_unchecked(is_na.sexp).iter() })
105105
.map(|(v, is_na)| {
106-
// we don't expect is.na to return NA's, but if it happens, we treat it as false
106+
// We don't expect is.na to return NA's, but if it happens, we treat it as false
107107
if is_na.unwrap_or(false) {
108108
FormattedValue::NA
109109
} else {
110-
// base::format defaults to using `trim=FALSE`
111-
// so it will add spaces to the end of the strings so all elements of the vector
112-
// have the same fixed width. We don't want this behavior in the data explorer,
110+
// `base::format` defaults to using `trim=FALSE`
111+
// So it will add spaces to the end of the strings causing all elements of the vector
112+
// to have the same fixed width. We don't want this behavior in the data explorer,
113113
// We tried passing `trim=TRUE` but this is unfortunately not supported for eg. `factors`:
114114
// > format(factor(c("aaaa", "a")), trim = TRUE)
115115
// [1] "aaaa" "a "
116116
//
117-
// so we will just trim the spaces manually, which is not ideal, but it's better than
117+
// So we will just trim the spaces manually, which is not ideal, but it's better than
118118
// having the values misaligned
119119
FormattedValue::Value(v.trim_matches(|x| x == ' ').to_string())
120120
}
121121
})
122122
.collect()
123123
},
124124
Err(_) => {
125-
// if we fail to get the is.na() values we will just return the formatted values
125+
// If we fail to get the is.na() values we will just return the formatted values
126126
// without additional treatments.
127127
formatted.into_iter().map(FormattedValue::Value).collect()
128128
},

0 commit comments

Comments
 (0)