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

Allow driver-specific environment variables #126

Merged
merged 12 commits into from
Jun 7, 2024
Merged

Allow driver-specific environment variables #126

merged 12 commits into from
Jun 7, 2024

Conversation

richfitz
Copy link
Member

@richfitz richfitz commented Jun 4, 2024

This will make the stan PR easier to understand. Allows a driver to provide its own default environment variables, which overlay over the hipercow defaults introduced in #125

@richfitz richfitz marked this pull request as ready for review June 4, 2024 08:04
Copy link
Contributor

@weshinsley weshinsley left a comment

Choose a reason for hiding this comment

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

All looks good - a couple of typos, and comments

R/configure.R Outdated Show resolved Hide resolved
R/configure.R Outdated Show resolved Hide resolved


DEFAULT_ENVVARS <- hipercow::hipercow_envvars( # nolint
"CMDSTAN" = "I:/cmdstan",
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this work when there are multiple installations within I:/cmdstan? In testing, I did this -

envvars <- c(hipercow_envvars("CMDSTAN" = "I:/cmdstan/cmdstan-2.35.0-rc3"),
             hipercow_envvars("CMDSTANR_USE_RTOOLS" = "TRUE"))

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, this works, though the mechanism in stan is byzantine. More details in the stan PR :)

envvars_combine(NULL,
hipercow_envvars(ENV1 = "AA", ENV5 = "EE", ENV6 = "FF")),
hipercow_envvars(ENV2 = "b", ENV3 = "c",
ENV1 = "AA", ENV5 = "EE", ENV6 = "FF"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Can I also remove a default environment variable by overwriting it with a NULL value? Eg, what if I have some very vindictive code that fails mysteriously if it detects the CMDSTAN env var is set...

Copy link
Member Author

Choose a reason for hiding this comment

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

The convention that withr uses is that a value of NA_character_ removes an envvar. This probably needs adding into c.hipercow_envvars

Copy link
Member Author

Choose a reason for hiding this comment

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

added support for this now

envvars_combine <- function(driver_envvars, task_envvars) {
c(getOption("hipercow.default_envvars", DEFAULT_ENVVARS),
driver_envvars,
task_envvars)
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to do

c(DEFAULT_ENVVARS,
  driver_envvars,
  getOption("hipercow.default_envvars"),
  task_envvars)

instead?

That's the behaviour suggested by the docs you've added.

On the other hand the DEFAULT_ENVVARS made some of the unit testing a bit annoying because they show up everywhere, so being able to disable them entirely was handy.

Copy link
Member Author

Choose a reason for hiding this comment

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

That was what I had, then changed the behaviour back to your previous one because the testing was awkward...

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, I've gone this way I documented, despite the test pain; I think it's better

DESCRIPTION Outdated Show resolved Hide resolved
@@ -70,6 +72,7 @@ c.hipercow_envvars <- function(...) {
}
ret <- rlang::inject(rbind(!!!inputs))
ret <- ret[!duplicated(ret$name, fromLast = TRUE), ]
Copy link
Member

Choose a reason for hiding this comment

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

Should I have added drop = FALSE here as well?

Copy link
Member Author

Choose a reason for hiding this comment

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

I've been doing a bunch with matrices recently where these are really important. I think that for data.frame's mine is superfluous actually - the drop here only would have an effect if we were subsetting columns (in which case with a single column will return the vector and not a data.frame of one column

@weshinsley weshinsley self-requested a review June 5, 2024 12:32
R/envvars.R Outdated Show resolved Hide resolved
@richfitz richfitz merged commit 0ba827d into main Jun 7, 2024
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants