Created
January 20, 2018 16:44
-
-
Save johnatasjmo/f6073976b5e1aac3d755ee1852a3aca5 to your computer and use it in GitHub Desktop.
R - Source all files within folder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setwd("~/rProgramming") | |
files.sources = list.files() | |
sapply(files.sources, source) |
excellent idea. just to add on to it. One may not aways be able to change the working directory and in that case, drop the setwd() function. Then, add the path to list.files() as list.files(path="~/rProgramming")
excellent idea. just to add on to it. One may not aways be able to change the working directory and in that case, drop the setwd() function. Then, add the path to list.files() as list.files(path="~/rProgramming")
Note - for this to work you also need to have full.names = TRUE
within the list.files function so that when you call source in the sapply function it has the path information for each file, which will be required since you didn't change your working directory. I.e. list.files(path="~/rProgramming", full.names = TRUE)
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you so much :)