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

future() arguments for passing R options and environment variables #480

Open
2 tasks
HenrikBengtsson opened this issue Mar 25, 2021 · 6 comments
Open
2 tasks

Comments

@HenrikBengtsson
Copy link
Owner

There are cases where one needs to customize options and environment variables used by the future. This can be done by explicitly setting those in the future expression, but that might be tedious, especially to make sure that they are unset afterward. Having future() do it for us is easier and avoids some code clutter. Here's one idea:

# Set env var 'FOO' with its currently set value, if set + set 'BAR' to "42"
f <- future(..., envvars = c("FOO", BAR = "42"))

# Set R options 'foo' with its currently set value, if set + set 'bar' to 42L
f <- future(..., options = c("foo", BAR = 42L))

These arguments should be exposed also in map-reduce APIs, e.g. future.apply and furrr.

Possible concerns

  • All types of options and environment variables should not be exported; is that something that future should monitor/protect again?
  • In R, certain environment variables must be set before launching R; is that something that future should monitor/protect again?
@yogat3ch
Copy link

yogat3ch commented Oct 20, 2021

[...]

Are there any workarounds you are aware of @HenrikBengtsson that we can use until this feature is added?

[...]

@HenrikBengtsson
Copy link
Owner Author

Are there any workarounds you are aware of @HenrikBengtsson that we can use until this feature is added?

The workaround would be to set the option or the environment variable manually inside the future where the values are passed via globals, e.g.

myenv <- Sys.getenv("MYENV")
myopt <- getOption("myopt")
f <- future({
  Sys.setenv(MYENV = myenv)
  options(myopt = myopt)
  ...
})

@yogat3ch
Copy link

yogat3ch commented Oct 20, 2021

Hi @HenrikBengtsson,
This doesn't work for functions because they retain the namespace that they were loaded in as the function environment, which is not available in the background process.

[...]

@HenrikBengtsson
Copy link
Owner Author

This doesn't work for functions because ...

Okay, so that sounds like a different problem than what this issue is about ("passing R options and environment variables"). Can you please bring this up on https://github.com/HenrikBengtsson/future/discussions instead.

@yogat3ch
Copy link

Sure, will do.

@yogat3ch
Copy link

Continued in #552

Repository owner deleted a comment from yogat3ch Oct 20, 2021
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

No branches or pull requests

2 participants