How to access to specify file in subfolder without change working directory In R?

后端 未结 4 408
名媛妹妹
名媛妹妹 2021-01-31 05:03

In R, I want to access to some file in subfolder. But I don\'t want to change working directory then move back. It lost time and long.

For exmaple, I working on /

4条回答
  •  故里飘歌
    2021-01-31 05:25

    I don't know if this is what you were looking for, but I have a library of files in a specific github folder that I source when I initialize a project in a new branch, and I found one solution online like this:

    setwd("~/repos/library/all_the_things")
    library_files <- list.files()
    sapply(library_files, source)
    

    which is great except now I'm starting every file in a directory where I wouldn't want to save plots etc., so I realized all it needed was this:

    library_files <- list.files("~/repos/library/all_the_things", full.name=T)
    sapply(library_files, source)
    

    and now it runs them without changing directories.

提交回复
热议问题