Skip to content

Commit d6656bb

Browse files
authored
Data Explorer: Display row names for matrix (#706)
* Display row.names for matrix * Add a regression test
1 parent 91e34b1 commit d6656bb

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

crates/ark/src/data_explorer/r_data_explorer.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,10 @@ impl RDataExplorer {
875875
}
876876

877877
fn r_get_state(&self) -> anyhow::Result<DataExplorerBackendReply> {
878+
let row_names = RFunction::new("base", "row.names")
879+
.add(self.table.get()?)
880+
.call_in(ARK_ENVS.positron_ns)?;
881+
878882
let state = BackendState {
879883
display_name: self.title.clone(),
880884
connected: Some(true),
@@ -893,10 +897,7 @@ impl RDataExplorer {
893897
row_filters: self.row_filters.clone(),
894898
column_filters: self.col_filters.clone(),
895899
sort_keys: self.sort_keys.clone(),
896-
has_row_labels: match self.table.get()?.attr("row.names") {
897-
Some(_) => true,
898-
None => false,
899-
},
900+
has_row_labels: !row_names.is_null(),
900901
supported_features: SupportedFeatures {
901902
get_column_profiles: GetColumnProfilesFeatures {
902903
support_status: SupportStatus::Supported,

crates/ark/tests/data_explorer.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,3 +1861,28 @@ fn test_frequency_table() {
18611861
});
18621862
});
18631863
}
1864+
1865+
#[test]
1866+
fn test_row_names_matrix() {
1867+
let _lock = r_test_lock();
1868+
1869+
// Convert mtcars to a matrix
1870+
let socket =
1871+
open_data_explorer_from_expression("as.matrix(mtcars)", Some("mtcars_matrix")).unwrap();
1872+
1873+
// Check row names are present
1874+
let req = DataExplorerBackendRequest::GetRowLabels(GetRowLabelsParams {
1875+
selection: ArraySelection::SelectIndices(DataSelectionIndices {
1876+
indices: vec![5, 6, 7, 8, 9],
1877+
}),
1878+
format_options: default_format_options(),
1879+
});
1880+
assert_match!(socket_rpc(&socket, req),
1881+
DataExplorerBackendReply::GetRowLabelsReply(row_labels) => {
1882+
let labels = row_labels.row_labels;
1883+
assert_eq!(labels[0][0], "Valiant");
1884+
assert_eq!(labels[0][1], "Duster 360");
1885+
assert_eq!(labels[0][2], "Merc 240D");
1886+
}
1887+
);
1888+
}

0 commit comments

Comments
 (0)