sourceFunctions: Source every R file in a folder

View source: R/sourceFunctions.R

sourceFunctionsR Documentation

Source every R file in a folder

Description

Loads all of an app's helper functions in one call, so app.R doesn't need a source() line per file. Every file ending in .R in the folder is sourced, in alphabetical order. Subfolders are not searched.

Usage

sourceFunctions(functionFolderPath, envir = parent.frame())

Arguments

functionFolderPath

Path to the folder holding the .R files, for example "Functions".

envir

Environment to load the functions into. Defaults to the one sourceFunctions() is called from, which in app.R is the global environment.

Details

A relative path is looked up from the working directory first. If it isn't found there, it is looked up from the project root with here::here().

Value

The paths of the sourced files, invisibly.

Examples

folder <- file.path(tempdir(), "Functions")
dir.create(folder, showWarnings = FALSE)
writeLines("addOne <- function(x) x + 1", file.path(folder, "addOne.R"))

sourceFunctions(folder)
addOne(1)

EZRShiny documentation built on Oct. 10, 2026, 5:08 p.m.