Source a bunch of files under given folders and/or subfolders

I wrote a function sourceDir() that can source all the functions under given folders and/or subfolders. This function is very much like “Set Path” in Matlab.Please visit this page to obtain the update to dated version.

To use it more efficiently, I suggest you put the function at some place, e.g. ~/workspace/R_utils/sourceDir.R, and write the following lines in .Rprofile file.

.my.env <- new.env()

Next time the function will be automatically loaded under a personal environment .my.env when R is launched and you can use it directly. The advantage of this is that rm(list=ls()) command will not remove the function sourceDir. But if you really want to remove sourceDir function, you can use rm(list=ls(all=TRUE)) command instead.

Leave a Reply

Your email address will not be published. Required fields are marked *