How to get R to recognize your working directory as its working directory?

后端 未结 9 801
鱼传尺愫
鱼传尺愫 2020-12-25 13:27

I use R under Windows on several machines.

I know you can set the working directory from within an R script, like this

setwd(\"C:/Documents and Setti         


        
9条回答
  •  半阙折子戏
    2020-12-25 13:35

    I put the following line in front of my scripts and it allows me to work across my computers.

    setwd(path.expand("~/path/to/working/directory/") )
    

    where ~ is = to your home directory.

    Sys.setenv(HOME = "path") or Sys.setenv(R_USER = "path") can both set the home directory.

    In my case, I work on several windows boxes, each have fairly different directory structures, but by setting the home directory properly I can sync code between computers and have them run properly on each one since where I run my R projects have similar directory structures.

提交回复
热议问题