Skip to content

Commit 3f8a0e0

Browse files
authored
Merge pull request #120 from imrehg/config-path
Set working directory for config.R correctly even if setwd is set outside
2 parents cbd61a1 + ea734bc commit 3f8a0e0

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tools/config.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,15 @@ if (!interactive()) {
574574
args <- commandArgs(TRUE)
575575
type <- args[[1]]
576576

577+
# preserve working directory
578+
owd <- getwd()
579+
on.exit(setwd(owd), add = TRUE)
580+
581+
# switch working directory to the calling scripts's directory as set
582+
# by the shell, in case the R working directory was set to something else
583+
basedir <- Sys.getenv("PWD", unset = ".")
584+
setwd(basedir)
585+
577586
# report start of execution
578587
package <- Sys.getenv("R_PACKAGE_NAME", unset = "<unknown>")
579588
fmt <- "** preparing to %s package '%s' ..."

0 commit comments

Comments
 (0)