MCPcopy Create free account
hub / github.com/REditorSupport/vscode-R / knitRmd

Method knitRmd

src/rmarkdown/knit.ts:241–293  ·  view source on GitHub ↗
(echo: boolean, outputFormat?: string)

Source from the content-addressed store, hash-verified

239 }
240
241 public async knitRmd(echo: boolean, outputFormat?: string): Promise<void> {
242 const textEditor = vscode.window.activeTextEditor;
243 if (!textEditor) {
244 void vscode.window.showWarningMessage('No text editor active.');
245 return;
246 }
247
248 const wad: vscode.TextDocument = textEditor.document;
249
250 // handle untitled rmd
251 if (textEditor.document.isUntitled) {
252 void vscode.window.showWarningMessage('Cannot knit an untitled file. Please save the document.');
253 await vscode.commands.executeCommand('workbench.action.files.save').then(() => {
254 if (!textEditor.document.isUntitled) {
255 void this.knitRmd(echo, outputFormat);
256 }
257 });
258 return;
259 }
260
261 const isSaved = await util.saveDocument(wad);
262 if (!isSaved) {
263 return;
264 }
265 let rDocumentPath = util.ToRStringLiteral(wad.fileName, '"');
266
267 if (echo) {
268 rDocumentPath = [rDocumentPath, 'echo = TRUE'].join(', ');
269 }
270
271 // allow users to opt out of background process
272 if (util.config().get<boolean>('rmarkdown.knit.useBackgroundProcess')) {
273 const busyPath = wad.uri.fsPath + (outputFormat ?? '');
274 if (this.busyUriStore.has(busyPath)) {
275 return;
276 }
277 this.busyUriStore.add(busyPath);
278 await this.renderDocument(
279 rDocumentPath,
280 wad.uri.fsPath,
281 path.basename(wad.uri.fsPath),
282 this.getYamlFrontmatter(wad.uri.fsPath),
283 outputFormat
284 );
285 this.busyUriStore.delete(busyPath);
286 } else {
287 if (outputFormat === undefined) {
288 void runTextInTerm(`rmarkdown::render(${rDocumentPath})`);
289 } else {
290 void runTextInTerm(`rmarkdown::render(${rDocumentPath}, '${outputFormat}')`);
291 }
292 }
293 }
294}

Callers 1

activateFunction · 0.80

Calls 7

renderDocumentMethod · 0.95
getYamlFrontmatterMethod · 0.95
runTextInTermFunction · 0.90
hasMethod · 0.80
addMethod · 0.80
deleteMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected