File tree Expand file tree Collapse file tree 2 files changed +11
-14
lines changed Expand file tree Collapse file tree 2 files changed +11
-14
lines changed Original file line number Diff line number Diff line change @@ -547,29 +547,25 @@ impl PositronVariable {
547
547
}
548
548
549
549
fn variable_length ( x : SEXP ) -> usize {
550
+ // Check for tabular data
551
+ if let Some ( info) = harp:: table_info ( x) {
552
+ return info. dims . num_cols as usize ;
553
+ }
554
+
555
+ // Otherwise treat as vector
550
556
let rtype = r_typeof ( x) ;
551
557
match rtype {
552
- LGLSXP | RAWSXP | INTSXP | REALSXP | CPLXSXP | STRSXP => unsafe {
558
+ LGLSXP | RAWSXP | INTSXP | REALSXP | CPLXSXP | STRSXP | LISTSXP => unsafe {
553
559
Rf_xlength ( x) as usize
554
560
} ,
555
561
VECSXP => unsafe {
556
- if r_inherits ( x, "POSIXlt" ) {
562
+ // TODO: Support vctrs types like record vectors
563
+ if r_inherits ( x, "POSIXlt" ) && r_typeof ( x) == VECSXP && r_length ( x) > 0 {
557
564
Rf_xlength ( VECTOR_ELT ( x, 0 ) ) as usize
558
- } else if r_is_data_frame ( x) {
559
- let dim = RFunction :: new ( "base" , "dim.data.frame" )
560
- . add ( x)
561
- . call ( )
562
- . unwrap ( ) ;
563
-
564
- INTEGER_ELT ( * dim, 0 ) as usize
565
565
} else {
566
566
Rf_xlength ( x) as usize
567
567
}
568
568
} ,
569
- LISTSXP => match pairlist_size ( x) {
570
- Ok ( n) => n as usize ,
571
- Err ( _) => 0 ,
572
- } ,
573
569
_ => 0 ,
574
570
}
575
571
}
Original file line number Diff line number Diff line change @@ -21,7 +21,8 @@ pub struct TableInfo {
21
21
}
22
22
23
23
// TODO: Might want to encode as types with methods so that we can make
24
- // assumptions about memory layout more safely
24
+ // assumptions about memory layout more safely. Also makes it possible
25
+ // to compute properties more lazily.
25
26
pub fn table_info ( x : SEXP ) -> Option < TableInfo > {
26
27
if r_is_data_frame ( x) {
27
28
return df_info ( x) . ok ( ) ;
You can’t perform that action at this time.
0 commit comments