Skip to content

Instantly share code, notes, and snippets.

View jasonsychau's full-sized avatar

Jason C jasonsychau

View GitHub Profile
@jasonsychau
jasonsychau / this_file_path.R
Last active July 2, 2023 01:35
R - get this file path
# a combination of
# https://stackoverflow.com/questions/1815606/determine-path-of-the-executing-script/15373917#15373917
# https://stackoverflow.com/questions/1815606/determine-path-of-the-executing-script/7585599#7585599
# https://stackoverflow.com/questions/47044068/get-the-path-of-current-script/47045368#47045368
# https://stackoverflow.com/questions/53512868/how-to-automatically-include-filepath-in-r-markdown-document/53516876#53516876
stub <- function() {}
thisPath <- function() {
cmdArgs <- commandArgs(trailingOnly = FALSE)
if (length(grep("^-f$", cmdArgs)) > 0) {
# R console option