Having trouble setting working directory

后端 未结 4 528
感情败类
感情败类 2021-02-05 06:11

I created a folder in order for it to be the main work directory meaning all the files I create go there, and files I read will be from there. For some reason after I created th

相关标签:
4条回答
  • 2021-02-05 06:46

    This may help... use the following code and browse the folder you want to set as the working folder

    setwd(choose.dir())
    
    0 讨论(0)
  • 2021-02-05 06:50

    The command setwd("~/") should set your working directory to your home directory. You might be experiencing problems because the OS you are using does not recognise "~/" as your home directory: this might be because of the OS, or it might be because of not having set that as your home directory elsewhere.

    As you have tagged the post using RStudio:

    • In the bottom right window move the tab over to 'files'.
    • Navigate through there to whichever folder you were planning to use as your working directory.
    • Under 'more' click 'set as working directory'

    You will now have set the folder as your working directory. Use the command getwd() to get the working directory as it is now set, and save that as a variable string at the top of your script. Then use setwd with that string as the argument, so that each time you run the script you use the same directory.

    For example at the top of my script I would have:

    work_dir <- "C:/Users/john.smith/Documents"
    setwd(work_dir)
    
    0 讨论(0)
  • 2021-02-05 06:53

    I just had this error message happen. When searching for why, I figured out that there's a related issue that can occur if you're not paying attention - the same error occurs if the directory you are trying to move into does not exist.

    0 讨论(0)
  • 2021-02-05 06:56

    Maybe it is the case that you have your path in couple of lines, you used enter to make it? If so, then part of you paths might look like that "/\nData/" instead of "/Data/", which causes the problem. Just set it to be in one line and issue is solved!

    0 讨论(0)
提交回复
热议问题