Skip to content
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

Merged
merged 3 commits into from
Nov 25, 2024
Merged

Support formulas #630

merged 3 commits into from
Nov 25, 2024

Conversation

dfalbel
Copy link
Contributor

@dfalbel dfalbel commented Nov 15, 2024

Build on top of #629
Addresses posit-dev/positron#4119

@dfalbel dfalbel changed the base branch from main to bugfix/honor-max-display-entries November 15, 2024 15:14
Base automatically changed from bugfix/honor-max-display-entries to main November 21, 2024 13:49
@dfalbel dfalbel force-pushed the feature/support-formula branch from b096d69 to ea1a3cd Compare November 21, 2024 15:25
@dfalbel dfalbel requested a review from lionel- November 22, 2024 12:04
Comment on lines +97 to +101
RAWSXP | LGLSXP | INTSXP | REALSXP | STRSXP | CPLXSXP => Self::from_default(value),
_ => Self::from_error(Error::Anyhow(anyhow!(
"Unexpected type {}",
r_type2char(r_typeof(value))
))),
Copy link
Contributor

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?

Copy link
Contributor Author

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:

_ => 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.

}

fn from_formula(value: SEXP) -> Self {
let display_value: Result<RObject, Error> = RFunction::new("base", "format")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
let display_value: Result<RObject, Error> = RFunction::new("base", "format")
let display_value: harp::Result<RObject> = RFunction::new("base", "format")

Copy link
Contributor Author

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.

crates/ark/src/variables/variable.rs Outdated Show resolved Hide resolved
crates/ark/src/variables/variable.rs Outdated Show resolved Hide resolved
#[test]
fn test_support_formula() {
r_task(|| {
let vars = inspect_from_expr("list(x = x ~ y + z + a)");
Copy link
Contributor

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 {.

Copy link
Contributor Author

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!

.call_in(ARK_ENVS.positron_ns)?
.try_into()?;

let mut display_value = String::with_capacity(MAX_DISPLAY_VALUE_LENGTH);
Copy link
Contributor

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.

Copy link
Contributor Author

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

@dfalbel dfalbel merged commit f3fffe3 into main Nov 25, 2024
6 checks passed
@dfalbel dfalbel deleted the feature/support-formula branch November 25, 2024 16:50
@github-actions github-actions bot locked and limited conversation to collaborators Nov 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants