Giter Club home page Giter Club logo

Comments (9)

gaborcsardi avatar gaborcsardi commented on July 27, 2024

That would be very fragile, as it is not clean what versions of what platforms need which env vars.

It would also be a breaking change, as existing code might rely on the inheritance of environment variables.

Nevertheless, if you want to do that, you can, by setting (nearly?) all existing env vars to NA.

from callr.

king-of-poppk avatar king-of-poppk commented on July 27, 2024

So if one wants to do that manually, they just wrap callr with a variant of the set(temporary); callr(...); set(previous) dance?

from callr.

gaborcsardi avatar gaborcsardi commented on July 27, 2024

No, you can use the env argument:

❯ Sys.setenv("FOO" = "bar")

❯ callr::r(function() Sys.getenv("FOO"))
[1] "bar"callr::r(function() Sys.getenv("FOO"), env = c(FOO = NA_character_))
[1] ""

from callr.

king-of-poppk avatar king-of-poppk commented on July 27, 2024

Ah. No, I meant to implement the logic I hinted at in the first post.

from callr.

gaborcsardi avatar gaborcsardi commented on July 27, 2024

Yes, if you want to start with a clean environment, set all current env vars to NA in the env argument.

from callr.

king-of-poppk avatar king-of-poppk commented on July 27, 2024

I guess since both Sys.unsetenv and callr's env parameter require explicit listing of the existing variables to "unset" it is only a question of API stability.

from callr.

gaborcsardi avatar gaborcsardi commented on July 27, 2024

No, do not use Sys.unsetenv(), that's not a good solution. R is single threaded, but occasionally there is a async code execution, e.g. finalizers might be triggered by the garbage collector, and they may use env vars.

Plus, callr's machinery might use env vars as well, so if you unset them before calling callr, then you might change callr's behavior.

from callr.

king-of-poppk avatar king-of-poppk commented on July 27, 2024

Good point!

from callr.

king-of-poppk avatar king-of-poppk commented on July 27, 2024

A better solution to reset the environment for the subprocess is to exploit a platform-dependent solution like env -i then.

from callr.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.