(rDocumentPath: string, docPath: string, docName: string, yamlParams: IYamlFrontmatter, outputFormat?: string)
| 34 | |
| 35 | |
| 36 | private async renderDocument(rDocumentPath: string, docPath: string, docName: string, yamlParams: IYamlFrontmatter, outputFormat?: string): Promise<DisposableProcess | undefined> { |
| 37 | const openOutfile: boolean = util.config().get<boolean>('rmarkdown.knit.openOutputFile') ?? false; |
| 38 | const knitWorkingDir = this.getKnitDir(knitDir, docPath); |
| 39 | const knitWorkingDirText = knitWorkingDir ? `${knitWorkingDir}` : ''; |
| 40 | const knitCommand = await this.getKnitCommand(yamlParams, rDocumentPath, outputFormat); |
| 41 | if (!knitCommand) { |
| 42 | return; |
| 43 | } |
| 44 | this.rPath = await util.getRpath(); |
| 45 | |
| 46 | const lim = '<<<vsc>>>'; |
| 47 | const re = new RegExp(`.*${lim}(.*)${lim}.*`, 'gms'); |
| 48 | const scriptValues = { |
| 49 | 'VSCR_KNIT_DIR': knitWorkingDirText, |
| 50 | 'VSCR_LIM': lim, |
| 51 | 'VSCR_KNIT_COMMAND': knitCommand |
| 52 | }; |
| 53 | |
| 54 | const callback = (dat: string) => { |
| 55 | const outputUrl = re.exec(dat)?.[0]?.replace(re, '$1'); |
| 56 | if (!outputUrl) { |
| 57 | return false; |
| 58 | } |
| 59 | if (openOutfile) { |
| 60 | const outFile = vscode.Uri.file(outputUrl); |
| 61 | if (fs.existsSync(outFile.fsPath)) { |
| 62 | void vscode.commands.executeCommand('vscode.open', outFile); |
| 63 | } else { |
| 64 | void vscode.window.showWarningMessage(`Could not find the output file at path: "${outFile.fsPath}"`); |
| 65 | } |
| 66 | } |
| 67 | return true; |
| 68 | }; |
| 69 | |
| 70 | if (util.config().get<boolean>('rmarkdown.knit.focusOutputChannel')) { |
| 71 | this.rMarkdownOutput.show(true); |
| 72 | } |
| 73 | |
| 74 | return await this.knitWithProgress( |
| 75 | { |
| 76 | workingDirectory: knitWorkingDirText, |
| 77 | fileName: docName, |
| 78 | filePath: rDocumentPath, |
| 79 | scriptArgs: scriptValues, |
| 80 | scriptPath: extensionContext.asAbsolutePath('R/rmarkdown/knit.R'), |
| 81 | rCmd: knitCommand, |
| 82 | rOutputFormat: outputFormat, |
| 83 | callback: callback |
| 84 | } |
| 85 | ); |
| 86 | |
| 87 | } |
| 88 | |
| 89 | private getYamlFrontmatter(docPath: string): IYamlFrontmatter { |
| 90 | const text = fs.readFileSync(docPath, 'utf8'); |
no test coverage detected