feat(r): add IO ops for R (+ minor touch to py reader)#47
Merged
Neclow merged 2 commits intosbhattlab:mainfrom May 23, 2025
Merged
feat(r): add IO ops for R (+ minor touch to py reader)#47Neclow merged 2 commits intosbhattlab:mainfrom
Neclow merged 2 commits intosbhattlab:mainfrom
Conversation
Collaborator
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)
Contributor
There was a problem hiding this comment.
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_newickin R with tests and documentation. - Export
create_label_mappingandapply_label_mappingin the Rust extendr module. - Update Python reader from
np.loadtxttonp.genfromtxtto 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#' @exportabove 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@exportand is missing from NAMESPACE. Add#' @exportand export it so users can call it.
save_newick <- function(vector_or_matrix, filepath, labels = NULL) {
r-phylo2vec/NAMESPACE:16
- The new functions
save_newickandload_newickare not exported; they should be added here to expose the I/O API.
export(load_p2v)
py-phylo2vec/phylo2vec/io/reader.py:34
dtype=Nonecan yield anobjectdtype for mixed int/float rows, leading to downstream errors. Consider explicitly handling numeric conversions or specifyingdtype=floatthen casting integers afterwards.
arr = np.genfromtxt(filepath, delimiter=delimiter, dtype=None)
r-phylo2vec/src/rust/src/lib.rs:2
- [nitpick] Importing
HashMapfromextendr_apimay be ambiguous. Usestd::collections::HashMapfor clarity unlessextendr_apispecifically 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 withmap_error returning aResultinstead of unwrapping.
ops::newick::apply_label_mapping(newick, &label_mapping_hash).unwrap()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.