-
Notifications
You must be signed in to change notification settings - Fork 17
Only force ALTREP compact row names (i.e. from duckplyr) if requested #745
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
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
87383dc
Only force ALTREP compact row names (i.e. from duckplyr) if requested
DavisVaughan 0251dc0
Rip out specific ALTREP support in favor of packages registering ark …
DavisVaughan ef9d06a
Note our care around `variable_length()`
DavisVaughan b00c1a1
Use `table.sexp`
DavisVaughan 4c1d331
Fix thinko
DavisVaughan 28e0bff
Bless duckplyr
DavisVaughan 29cca6c
Remove duplicate check done by `r_is_data_frame()`
DavisVaughan a61599a
Move nrow/ncol into static methods
DavisVaughan 1f42973
Turn `mat_dim()` into `Matrix::dim()`
DavisVaughan ec35847
Add `get_attribute()` and friends to `RObject`
DavisVaughan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use libr::*; | ||
|
||
use crate::exec::RFunction; | ||
use crate::exec::RFunctionExt; | ||
use crate::utils::*; | ||
use crate::vector::Vector; | ||
use crate::CharacterVector; | ||
use crate::RObject; | ||
|
||
/// Column names | ||
/// | ||
/// Column names represent an optional character vector of names. This class is mostly | ||
/// useful for ergonomics, since [ColumnNames::get_unchecked()] will propagate [None] | ||
/// when used on a vector without column names. | ||
pub struct ColumnNames { | ||
names: Option<CharacterVector>, | ||
} | ||
|
||
impl ColumnNames { | ||
pub fn new(names: SEXP) -> Self { | ||
let names = if r_typeof(names) == STRSXP { | ||
Some(unsafe { CharacterVector::new_unchecked(names) }) | ||
} else { | ||
None | ||
}; | ||
Self { names } | ||
} | ||
|
||
pub fn from_data_frame(x: SEXP) -> crate::Result<Self> { | ||
if !r_is_data_frame(x) { | ||
return Err(crate::anyhow!("`x` must be a data frame.")); | ||
} | ||
let Some(column_names) = RObject::view(x).get_attribute_names() else { | ||
return Err(crate::anyhow!("`x` must have column names.")); | ||
}; | ||
Ok(Self::new(column_names.sexp)) | ||
} | ||
|
||
pub fn from_matrix(x: SEXP) -> crate::Result<Self> { | ||
if !r_is_matrix(x) { | ||
return Err(crate::anyhow!("`x` must be a matrix.")); | ||
} | ||
let column_names = RFunction::from("colnames").add(x).call()?; | ||
Ok(Self::new(column_names.sexp)) | ||
} | ||
|
||
pub fn get_unchecked(&self, index: isize) -> Option<String> { | ||
if let Some(names) = &self.names { | ||
if let Some(name) = names.get_unchecked(index) { | ||
if name.len() > 0 { | ||
return Some(name); | ||
} | ||
} | ||
} | ||
None | ||
} | ||
} |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.