Skip to content

Commit ea734bc

Browse files
committed
Set working directory for config.R correctly even if setwd is set outside
`setwd` can be set in a `~/.Rprofile` or `Rprofile.site`, to provide a default path when R opens. This however confuses the config script, as the R working path might then be different from the system path from where the script is called. This patch sets the current R code's working directory to the same as it was previously assumed, the calling scripts (`configure` or `cleanup`) folders, through the `PWD` shell env var. After this the relative paths for the tools folder becomes correct. Signed-off-by: Gergely Imreh <gergely.imreh@faculty.ai>
1 parent cbd61a1 commit ea734bc

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)