risks of using setwd() in a script?

前端 未结 6 2145
抹茶落季
抹茶落季 2020-12-04 15:59

I\'ve heard it said that it is bad practice to use setwd() in a script.

  • What are the risks/dangers associated with it?
  • What are bett
6条回答
  •  半阙折子戏
    2020-12-04 16:18

    To make things a bit more portable where I work we all put this in a Rprofile

    hdrive=
    switch(Sys.info()[[1]],
    'Linux'="/mnt/hdrive",
    'Windows'="H:/",
    "Darwin"="/Volumes/hdrive/mnt/hdrive"
    )
    

    So i always have that variable to get me to our shared drive. Then in my script we can write

    setwd(paste(hdrive,"/relative/path/",sep="/"))
    

    So that gets us around some of the problems that others are talking about.

提交回复
热议问题