Skip to content

feat(r): add IO ops for R (+ minor touch to py reader)#47

Merged
Neclow merged 2 commits intosbhattlab:mainfrom
Neclow:r_io
May 23, 2025
Merged

feat(r): add IO ops for R (+ minor touch to py reader)#47
Neclow merged 2 commits intosbhattlab:mainfrom
Neclow:r_io

Conversation

@Neclow
Copy link
Collaborator

@Neclow Neclow commented May 23, 2025

  • Setup I/O operations for r-phylo2vec
  • use np.genfromtxt for Python to infer dtypes (to opt for vector or matrix)

@Neclow Neclow requested a review from Copilot May 23, 2025 22:59
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Add input/output support for R, expose new label mapping functions in the Rust backend, bump the Rust package version, and switch Python reader to np.genfromtxt for dtype inference.

  • Introduce load_p2v, save_p2v, load_newick, save_newick in R with tests and documentation.
  • Export create_label_mapping and apply_label_mapping in the Rust extendr module.
  • Update Python reader from np.loadtxt to np.genfromtxt to better infer integer vs. float arrays.

Reviewed Changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated no comments.

Show a summary per file
File Description
r-phylo2vec/R/io.R Added R I/O functions (load_p2v, save_p2v, load_newick, save_newick) and a path checker
r-phylo2vec/tests/testthat/test_io.R Added tests for round‐trip save/load of vectors and matrices, and error on unsupported extension
r-phylo2vec/src/rust/src/lib.rs Exported new label-mapping functions and fixed a typo
r-phylo2vec/src/rust/Cargo.toml Bumped version from 1.0.0 to 1.1.0
r-phylo2vec/scripts/install-package.R Removed cleanup code
r-phylo2vec/man/*.Rd Added documentation for new I/O and label-mapping functions
r-phylo2vec/R/extendr-wrappers.R Added R wrappers for the two new Rust functions
r-phylo2vec/NAMESPACE Exported new extendr wrappers and load_p2v
py-phylo2vec/phylo2vec/io/reader.py Switched from np.loadtxt to np.genfromtxt with dtype=None
Comments suppressed due to low confidence (7)

r-phylo2vec/scripts/install-package.R:13

  • [nitpick] The cleanup code that removed temporary files was removed. If those files are no longer needed, consider documenting why the cleanup step is dropped or restoring it to avoid leaving artifacts.
devtools::install(args[1], build = FALSE)

r-phylo2vec/R/io.R:60

  • load_newick() is not marked with @export, so it won't be available to package users. Add #' @export above its definition and include it in NAMESPACE.
load_newick <- function(filepath_or_buffer) {

r-phylo2vec/R/io.R:76

  • save_newick() is not marked with @export and is missing from NAMESPACE. Add #' @export and export it so users can call it.
save_newick <- function(vector_or_matrix, filepath, labels = NULL) {

r-phylo2vec/NAMESPACE:16

  • The new functions save_newick and load_newick are not exported; they should be added here to expose the I/O API.
export(load_p2v)

py-phylo2vec/phylo2vec/io/reader.py:34

  • dtype=None can yield an object dtype for mixed int/float rows, leading to downstream errors. Consider explicitly handling numeric conversions or specifying dtype=float then casting integers afterwards.
arr = np.genfromtxt(filepath, delimiter=delimiter, dtype=None)

r-phylo2vec/src/rust/src/lib.rs:2

  • [nitpick] Importing HashMap from extendr_api may be ambiguous. Use std::collections::HashMap for clarity unless extendr_api specifically re-exports it.
use extendr_api::HashMap;

r-phylo2vec/src/rust/src/lib.rs:288

  • Calling unwrap() can panic on bad input. Consider propagating an error back to R with map_err or returning a Result instead of unwrapping.
ops::newick::apply_label_mapping(newick, &label_mapping_hash).unwrap()

@Neclow Neclow merged commit e41dd7c into sbhattlab:main May 23, 2025
7 checks passed
@Neclow Neclow deleted the r_io branch May 23, 2025 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants