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

Standard evaluation version of functions #67

Closed
richierocks opened this issue Sep 13, 2016 · 6 comments
Closed

Standard evaluation version of functions #67

richierocks opened this issue Sep 13, 2016 · 6 comments
Assignees
Milestone

Comments

@richierocks
Copy link

richierocks commented Sep 13, 2016

Standard evaluation is often better for when you want to include code in your own packages. Do you plan to include standard evaluation versions of the functions?

I'm thinking of the dplyr style, for example filter vs. filter_. So you could include add_variable_, set_obejctive_, etc.

I think that most of the logic is handled by the lazyeval package, so it shouldn't be too tricky to implement.

@dirkschumacher
Copy link
Owner

Sounds like a good idea. How would that api look exactly? Pass in a lazyeval object or a character string?

@richierocks
Copy link
Author

I think you want something like this:

setGeneric("set_objective", function(model, expression, direction = "max") {
  set_objective_(model, expression = lazyeval::lazy(expression), direction = direction)
}

setGeneric("set_objective_", function(model, expression, direction = "max") {
  # As the current set_objective fn, but without calls to substitute
}

expression can be passed to set_objective_ as a formula, string, or quoted expression.

BTW, if direction can only be "min" or "max", then you can check it by changing the signature to

function(model, expression, direction = c("max", "min"))

then calling direction <- match.arg(direction) in the function body.

@dirkschumacher
Copy link
Owner

Cool thanks. Will look into this. Indeed, maybe I should use lazyeval instead of base R's eval/substitute constructs.

@dirkschumacher
Copy link
Owner

@richierocks Added a first version. If you have any comments on the code or other ideas let me know

@dirkschumacher
Copy link
Owner

:shipit: I close the issue for now.

@dirkschumacher
Copy link
Owner

Still needs a solution for variable and constraint quantifiers

@dirkschumacher dirkschumacher self-assigned this Oct 6, 2016
@dirkschumacher dirkschumacher added this to the CRAN 1.0 milestone Oct 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants