From 090b01e4524876261f6d5aa8cbb03ad5e975fcde Mon Sep 17 00:00:00 2001 From: Xavier Olive Date: Tue, 26 Oct 2021 09:33:06 +0200 Subject: [PATCH 1/5] get knit command from settings --- src/rmarkdown/knit.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/rmarkdown/knit.ts b/src/rmarkdown/knit.ts index b256ded80..735f34631 100644 --- a/src/rmarkdown/knit.ts +++ b/src/rmarkdown/knit.ts @@ -104,8 +104,10 @@ export class RMarkdownKnitManager extends RMarkdownManager { yamlParams['site'] = await this.findSiteParam(); } + const knitCommandCfg: string = util.config().get('rmarkdown.knit.command') ?? ''; + // precedence: - // knit > site > none + // knit > site > configuration > none if (yamlParams?.['knit']) { const knitParam = yamlParams['knit']; knitCommand = outputFormat ? @@ -115,6 +117,10 @@ export class RMarkdownKnitManager extends RMarkdownManager { knitCommand = outputFormat ? `rmarkdown::render_site(${docPath}, output_format = '${outputFormat}')` : `rmarkdown::render_site(${docPath})`; + } else if (knitCommandCfg !== '') { + knitCommand = outputFormat ? + `${knitCommandCfg}(${docPath}, output_format = '${outputFormat}')` : + `${knitCommandCfg}(${docPath})`; } else { knitCommand = outputFormat ? `rmarkdown::render(${docPath}, output_format = '${outputFormat}')` : From fcbe1c8c207a4190c7d7c1d97b078342f10ba54a Mon Sep 17 00:00:00 2001 From: Xavier Olive Date: Tue, 26 Oct 2021 09:43:17 +0200 Subject: [PATCH 2/5] configuration option description --- package.json | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/package.json b/package.json index 327f103c2..9a9a8dc46 100644 --- a/package.json +++ b/package.json @@ -1316,6 +1316,11 @@ "default": false, "markdownDescription": "Should the output file be opened automatically when using knit?\n\nRequires `#r.rmarkdown.knit.useBackgroundProcess#` to be set to `true`." }, + "r.rmarkdown.knit.command": { + "type": "string", + "default": "", + "markdownDescription": "Default command used to knit a Rmd file." + }, "r.rmarkdown.knit.defaults.knitWorkingDirectory": { "type": "string", "default": "document directory", From d128ff176f7517f49140af1f1ef2341ff829a826 Mon Sep 17 00:00:00 2001 From: Kun Ren Date: Fri, 29 Oct 2021 13:44:17 +0800 Subject: [PATCH 3/5] Refine description --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9a9a8dc46..23800bf9c 100644 --- a/package.json +++ b/package.json @@ -1319,7 +1319,7 @@ "r.rmarkdown.knit.command": { "type": "string", "default": "", - "markdownDescription": "Default command used to knit a Rmd file." + "markdownDescription": "Command used to knit a Rmd file if not specified by the frontmatter." }, "r.rmarkdown.knit.defaults.knitWorkingDirectory": { "type": "string", From 3595eda4231cd3c184fcaf441702366d8b013094 Mon Sep 17 00:00:00 2001 From: Kun Ren Date: Fri, 29 Oct 2021 13:50:22 +0800 Subject: [PATCH 4/5] Use a default value --- package.json | 2 +- src/rmarkdown/knit.ts | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 23800bf9c..861c79171 100644 --- a/package.json +++ b/package.json @@ -1318,7 +1318,7 @@ }, "r.rmarkdown.knit.command": { "type": "string", - "default": "", + "default": "rmarkdown::render", "markdownDescription": "Command used to knit a Rmd file if not specified by the frontmatter." }, "r.rmarkdown.knit.defaults.knitWorkingDirectory": { diff --git a/src/rmarkdown/knit.ts b/src/rmarkdown/knit.ts index 735f34631..671bdfe85 100644 --- a/src/rmarkdown/knit.ts +++ b/src/rmarkdown/knit.ts @@ -104,8 +104,6 @@ export class RMarkdownKnitManager extends RMarkdownManager { yamlParams['site'] = await this.findSiteParam(); } - const knitCommandCfg: string = util.config().get('rmarkdown.knit.command') ?? ''; - // precedence: // knit > site > configuration > none if (yamlParams?.['knit']) { @@ -117,14 +115,11 @@ export class RMarkdownKnitManager extends RMarkdownManager { knitCommand = outputFormat ? `rmarkdown::render_site(${docPath}, output_format = '${outputFormat}')` : `rmarkdown::render_site(${docPath})`; - } else if (knitCommandCfg !== '') { - knitCommand = outputFormat ? - `${knitCommandCfg}(${docPath}, output_format = '${outputFormat}')` : - `${knitCommandCfg}(${docPath})`; } else { + const cmd = util.config().get('rmarkdown.knit.command'); knitCommand = outputFormat ? - `rmarkdown::render(${docPath}, output_format = '${outputFormat}')` : - `rmarkdown::render(${docPath})`; + `${cmd}(${docPath}, output_format = '${outputFormat}')` : + `${cmd}(${docPath})`; } return knitCommand.replace(/['"]/g, '\''); From 362e355910f6f4d54edfeb9de4aefcc1506bc1cd Mon Sep 17 00:00:00 2001 From: Kun Ren Date: Fri, 29 Oct 2021 13:52:32 +0800 Subject: [PATCH 5/5] Update comment --- src/rmarkdown/knit.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rmarkdown/knit.ts b/src/rmarkdown/knit.ts index 671bdfe85..55aeb1f2a 100644 --- a/src/rmarkdown/knit.ts +++ b/src/rmarkdown/knit.ts @@ -105,7 +105,7 @@ export class RMarkdownKnitManager extends RMarkdownManager { } // precedence: - // knit > site > configuration > none + // knit > site > configuration if (yamlParams?.['knit']) { const knitParam = yamlParams['knit']; knitCommand = outputFormat ?