-
Notifications
You must be signed in to change notification settings - Fork 15
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
Support formulas #630
Support formulas #630
Conversation
b096d69
to
ea1a3cd
Compare
RAWSXP | LGLSXP | INTSXP | REALSXP | STRSXP | CPLXSXP => Self::from_default(value), | ||
_ => Self::from_error(Error::Anyhow(anyhow!( | ||
"Unexpected type {}", | ||
r_type2char(r_typeof(value)) | ||
))), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why this new restriction? For explicitness?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I taught that capturing an unexpected type here would be more explicit.
Before that, for example, the formula support error was being captured at:
ark/crates/harp/src/vector/formatted_vector.rs
Lines 112 to 115 in 92ce2f7
_ => Err(Error::UnexpectedType(r_typeof(vector), vec![ | |
RAWSXP, LGLSXP, INTSXP, REALSXP, STRSXP, CPLXSXP, | |
])), | |
} |
Which is fine, but, AFAICT we should only use FormattedVector
for vector like objects.
crates/ark/src/variables/variable.rs
Outdated
} | ||
|
||
fn from_formula(value: SEXP) -> Self { | ||
let display_value: Result<RObject, Error> = RFunction::new("base", "format") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let display_value: Result<RObject, Error> = RFunction::new("base", "format") | |
let display_value: harp::Result<RObject> = RFunction::new("base", "format") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I simplified the error handling by returning an anyhow::Result
in the form_formula
method and handling it in from_language
.
#[test] | ||
fn test_support_formula() { | ||
r_task(|| { | ||
let vars = inspect_from_expr("list(x = x ~ y + z + a)"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs a test with multiline deparsing, e.g. with {
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed and added a test for this!
crates/ark/src/variables/variable.rs
Outdated
.call_in(ARK_ENVS.positron_ns)? | ||
.try_into()?; | ||
|
||
let mut display_value = String::with_capacity(MAX_DISPLAY_VALUE_LENGTH); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to join lines with ;
(with trailing space) and add a space after {
and before }
. But the deparser might add lines in other cases too, so I guess we can't easily do that.
I would have just ellipsised after the first line to avoid this issue, but your approach allows seeing more of the contents. I'll leave it up to you to decide what is best.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh I missed that. I decided to just add an ellipsis after the first {
: c812b8f
Build on top of #629
Addresses posit-dev/positron#4119