Created
July 13, 2016 17:48
-
-
Save sjessa/96b48caaef2e1df425d9124a0c464e2b to your computer and use it in GitHub Desktop.
dynamically source a file in R
This file contains 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
# Source a file in the same directory as the script regardless of the | |
# working directory from which the script is being called. | |
# Works in conjunction with argparser. | |
# Adapted from http://stackoverflow.com/a/1815743 | |
command <- commandArgs(trailingOnly = FALSE) | |
script_name <- sub("--file=", "", command[grep("--file=", command)]) | |
script_path <- dirname(script_name) | |
my_functions <- file.path(script_path, "functions.R") | |
source(my_functions, chdir = TRUE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment