jeromyanglim / learning_r

assorted notes to self while learning R
1 stars 0 forks source link

How to source all .R files in a directory? #22

Closed jeromyanglim closed 12 years ago

jeromyanglim commented 12 years ago

The help for the source function has an example of sourcing a directory:

 sourceDir <- function(path, trace = TRUE, ...) {
    for (nm in list.files(path, pattern = "\\.[RrSsQq]$")) {
       if(trace) cat(nm,":")           
       source(file.path(path, nm), ...)
       if(trace) cat("\n")
    }
 }