1- # ' @title Determines the path of the currently running script
2- # ' @description \R does not store nor export the path of the currently running
1+ # ' Determines the path of the currently running script
2+ # '
3+ # ' @description
4+ # ' `r lifecycle::badge("soft-deprecated")`
5+ # '
6+ # ' \R does not store nor export the path of the currently running
37# ' script. This is an attempt to circumvent this limitation by applying
48# ' heuristics (such as call stack and argument inspection) that work in many
59# ' cases.
1216# ' or run with `Rscript` or using the `--file` parameter to the
1317# ' `R` executable. For code run with `Rscript`, the exact value
1418# ' of the parameter passed to `Rscript` is returned.
19+ # '
20+ # ' @section Life cycle:
21+ # '
22+ # ' These functions are now available in the \pkg{whereami} package.
23+ # '
1524# ' @return The path of the currently running script, NULL if it cannot be
1625# ' determined.
1726# ' @seealso [base::source()], [utils::Rscript()], [base::getwd()]
1827# ' @references [https://stackoverflow.com/q/1815606/946850]()
1928# ' @author Kirill Müller, Hadley Wickham, Michael R. Head
29+ # ' @keywords internal
2030# ' @examples
2131# ' \dontrun{
2232# ' thisfile()
2333# ' }
2434# ' @export
2535thisfile <- function () {
36+ lifecycle :: deprecate_soft(
37+ " 2.0.0" ,
38+ " rprojroot::thisfile()" ,
39+ " whereami::thisfile()"
40+ )
41+
2642 if (! is.null(res <- thisfile_source())) {
2743 res
2844 } else if (! is.null(res <- thisfile_r())) {
@@ -39,6 +55,12 @@ thisfile <- function() {
3955# ' @rdname thisfile
4056# ' @export
4157thisfile_source <- function () {
58+ lifecycle :: deprecate_soft(
59+ " 2.0.0" ,
60+ " rprojroot::thisfile_source()" ,
61+ " whereami::thisfile_source()"
62+ )
63+
4264 for (i in - (1 : sys.nframe())) {
4365 if (identical(args(sys.function(i )), args(base :: source ))) {
4466 return (normalizePath(sys.frame(i )$ ofile ))
@@ -52,6 +74,12 @@ thisfile_source <- function() {
5274# ' @importFrom utils tail
5375# ' @export
5476thisfile_r <- function () {
77+ lifecycle :: deprecate_soft(
78+ " 2.0.0" ,
79+ " rprojroot::thisfile_r()" ,
80+ " whereami::thisfile_r()"
81+ )
82+
5583 cmd_args <- commandArgs(trailingOnly = FALSE )
5684 if (! grepl(" ^R(?:|term)(?:|[.]exe)$" , basename(cmd_args [[1L ]]), ignore.case = TRUE )) {
5785 return (NULL )
@@ -77,6 +105,12 @@ thisfile_r <- function() {
77105# ' @importFrom utils tail
78106# ' @export
79107thisfile_rscript <- function () {
108+ lifecycle :: deprecate_soft(
109+ " 2.0.0" ,
110+ " rprojroot::thisfile_rscript()" ,
111+ " whereami::thisfile_rscript()"
112+ )
113+
80114 cmd_args <- commandArgs(trailingOnly = FALSE )
81115 if (! grepl(" ^R(?:term|script)(?:|[.]exe)$" , basename(cmd_args [[1L ]]), ignore.case = TRUE )) {
82116 return (NULL )
@@ -100,6 +134,12 @@ thisfile_rscript <- function() {
100134# ' @rdname thisfile
101135# ' @export
102136thisfile_knit <- function () {
137+ lifecycle :: deprecate_soft(
138+ " 2.0.0" ,
139+ " rprojroot::thisfile_knit()" ,
140+ " whereami::thisfile_knit()"
141+ )
142+
103143 if (requireNamespace(" knitr" )) {
104144 return (knitr :: current_input(dir = TRUE ))
105145 }
0 commit comments