Skip to content

Commit b306fbd

Browse files
authored
Merge pull request #4749 from quarto-dev/R-working-dir
2 parents f8d03d4 + 793d1d6 commit b306fbd

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/execute/rmd.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ async function callR<T>(
195195
outputFilter?: (output: string) => string,
196196
reportError = true,
197197
): Promise<T> {
198-
// establish cwd for execute (the current dir if there is an renv
198+
// establish cwd for our R scripts (the current dir if there is an renv
199199
// otherwise the project dir if specified)
200-
const cwd = withinActiveRenv() ? undefined : projectDir;
200+
const cwd = withinActiveRenv() ? Deno.cwd() : projectDir ?? Deno.cwd();
201201

202202
// create a temp file for writing the results
203203
const resultsFile = Deno.makeTempFileSync(
@@ -208,6 +208,7 @@ async function callR<T>(
208208
action,
209209
params,
210210
results: resultsFile,
211+
wd: cwd,
211212
});
212213

213214
try {

src/resources/rmd/rmd.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@
137137
request <- jsonlite::parse_json(input, simplifyVector = TRUE)
138138
params <- request$params
139139

140+
# Ensuring expected working dir for Quarto
141+
# R process workding may be changed by some workflows (in ~/.Rprofile)
142+
# https://github.com/quarto-dev/quarto-cli/issues/2646
143+
setwd(request$wd) # no need to reset it as R process is closed by R
144+
140145
# source in helper functions if we have a resourceDir
141146
if (!is.null(params$resourceDir)) {
142147
res_dir <- file.path(params$resourceDir, "rmd")

0 commit comments

Comments
 (0)