Skip to content

Add a command to knit the current Rmd file #121

@a-torgovitsky

Description

@a-torgovitsky

Is your feature request related to a problem? Please describe.
I find it frustrating to have to continually jump to the R window and type `rmarkdown::render("filename.Rmd") when developing an R markdown file.

Describe the solution you'd like
A command that works like runSource, except it knits the current file.

I don't know anything about developing VS code plugins, but here's a stab at a function that might work? I just copied runSource, changed source and removed setFocus.

    function knitSource(echo: boolean)  {
        const wad = window.activeTextEditor.document;
        wad.save();
        let rPath = ToRStringLiteral(wad.fileName, '"');
        let encodingParam = config.get("source.encoding") as string;
        if (encodingParam) {
            encodingParam = `encoding = "${encodingParam}"`;
            rPath = [rPath, encodingParam].join(", ");
        }
        if (echo) {
            rPath = [rPath, "echo = TRUE"].join(", ");
        }
        if (!rTerm) {
            const success = createRTerm(true);
            if (!success) { return; }
        }
        rTerm.sendText(`rmarkdown::render(${rPath})`);
    }

Describe alternatives you've considered
N/A

Additional context
N/A

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions