Skip to content

Commit

Permalink
Change root criteria in rprojroot::find_root
Browse files Browse the repository at this point in the history
Add rprojroot::has_file(".git") as an alternative root criterion to
handle linked git working trees created by `git worktree add` in
rprojroot::find_root.
  • Loading branch information
logstar committed Jul 22, 2021
1 parent f9f6d17 commit eca90e5
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions analyses/long-format-table-utils/annotator/annotator-cli.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


# source annotator-api.R to get the annotate_long_format_table function --------
# Detect the ".git" folder -- this will in the project root directory. Use
# Detect the ".git" folder -- this will be in the project root directory. Use
# this as the root directory to ensure proper execution, no matter where it is
# called from.
#
Expand All @@ -33,10 +33,22 @@
#
# root_dir is the absolute path of OpenPedCan-analysis
#
# Adapted from the oncoprint-landscape module.
# Adapted from the oncoprint-landscape module
#
# rprojroot::has_file(".git/index") returns a rprojroot::root_criterion, and
# main git working tree, created by git clone and git init, has the .git/index
# file
#
# rprojroot::has_file(".git") returns a rprojroot::root_criterion, and linked
# git working tree, created by git worktree add, has the .git file
#
# "Root criteria can be combined with the | operator. The result is a
# composite root criterion that requires either of the original criteria to
# match." -- help("root_criterion", "rprojroot") rprojroot_1.3-2
tryCatch(
{
root_dir <- rprojroot::find_root(rprojroot::has_file(".git/index"))
root_dir <- rprojroot::find_root(
rprojroot::has_file(".git/index") | rprojroot::has_file(".git"))
},
error = function(err_cond) {
# adapted from http://adv-r.had.co.nz/Exceptions-Debugging.html
Expand Down

0 comments on commit eca90e5

Please sign in to comment.