when do you want to set up new environments in R

后端 未结 3 1128
故里飘歌
故里飘歌 2021-02-19 00:27

per the discussion of R programming styles, I saw someone once said he puts all his custom function into a new environment and attach it. I also remember R environment maybe use

3条回答
  •  伪装坚强ぢ
    2021-02-19 00:37

    If your ecosystem of data and code has grown large enough that you are considering isolating it in an environment, you are better off creating a package. A package gives you much more support for:

    • Managing a project that is growing large and complex by separating code and data into files so there is less to dig through at one time.

    • A package makes it dead simple to hand off your work to someone else so they can use your code and data.

    • A package provides additional support for documentation and reporting.

    Setting up a package for R is so easy, just call package.skeleton(), that every project I work on gets its code and data stored in a package.

    The only time I use environments is when I need to isolate a run of some code, usually a script written by someone else, so that it's side effects and variable names don't get crossed with mine. I do this by evalq(source('someScript.R', local=TRUE), SomeEnvironment).

提交回复
热议问题