Skip to content

set rmarkdown context into knit_opts during render #32

Closed

Description

@jjallaire

opts_knit$set(rmarkdown.pandoc.to = "html")
opts_knit$set(rmarkdown.version = 2)

Activity

  1. Thell commented on Mar 28, 2014

    @Thell

    Shouldn't this be null?

        <!-- rmarkdown v1 -->
    
        ```{r}
        knitr::opts_knit$get("rmarkdown.version")
        ```
    
        ## [1] 2
    
  2. jjallaire commented on Mar 28, 2014

    @jjallaire
    MemberAuthor

    No, the rmarkdown v1 comment is just something to tell RStudio to use markdown::markdownToHTML rather than rmarkdown::render. By the time you get into rmarkdown::render you are using R Markdown v2 (it doesn't know anything about this special comment).

    Your test would therefore look like this:

    rmd_version <- knitr::opts_knit$get("rmarkdown.version")
    if (is.null(rmd_version)) {
    
         # using the markdown package
    
    } else if (rmd_version >= 2) {
    
       # using the rmarkdown package
    }
  3. Thell commented on Mar 31, 2014

    @Thell

    It seems the rmarkdown v1 comment can be used, it just lags by one render. Having this flag available is making testing of hooks much quicker than switching to another instance/server.

        ---
        output: html_document
        ---
    
        ```{r, echo=FALSE}
        rmd.version <- knitr::opts_knit$get("rmarkdown.version")
    
        if( is.null(rmd.version) ) {
          print("using hook_markdown_v1")
        } else {
          print("using hook_markdown_latest")
        }
        ```
    

    Run one: ## [1] "using hook_markdown_latest"

    add: <!-- rmarkdown v1 -->

    Run one: ## [1] "using hook_markdown_latest"
    Run two: ## [1] "using hook_markdown_v1"

    remove: <!-- rmarkdown v1 -->

    Run one: ## [1] "using hook_markdown_v1"
    Run two: ## [1] "using hook_markdown_latest"

  4. github-actions commented on Nov 3, 2020

    @github-actions

    This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

  5. locked as resolved and limited conversation to collaborators on Nov 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions