R code that writes markdown code

Is there a way to have R write a markdown list - one bullet for every element in the vector?
I'm kinda hacking it right now by using kable tables and putting a

  • element in front of each row, but it still looks like a table, not a list.

    [Update] I'm getting closer? with this:

  • Hi @Norcalbiostat!

    Have you tried pander — it defines methods for an enormous slew of R objects and classes and creates Markdown representations of them. Obviously there are some assumptions involved in doing that, but if you don't like pander's choices, it has many options you can tweak. And of course you can use its code and tools as inspiration for your own :smile:

    library(pander)
    
    these <- c("Antelope", "Buttonloop", "Canteloupe")
    
    those <- list(
      teeny = "Elephant",
      tiny = "Whale",
      itty = "Hippopotamus",
      bitty = "Rhinoceros"
    )
    
    pander(these)
    

    Antelope, Buttonloop and Canteloupe

    
    pander(those)
    
    • teeny: Elephant
    • tiny: Whale
    • itty: Hippopotamus
    • bitty: Rhinoceros

    Created on 2019-06-16 by the reprex package (v0.3.0)

    The comment boxes on this site parse Markdown, of course, which is both illustrative and confusing in this case! Here's what the raw pander output looked like:

    *Antelope*, *Buttonloop* and *Canteloupe*

    
      - **teeny**: Elephant
      - **tiny**: Whale
      - **itty**: Hippopotamus
      - **bitty**: Rhinoceros
    
    <!-- end of list -->
    

    (HTML comments are valid in Markdown)

    8 Likes

    You can also generate R code this 2 ways
    This vector can be transform in bullet list

    vec <- letters[1:4]
    

    by generating markdown string

    glue::glue("* {vec}")
    
    • a
    • b
    • c
    • d

    by generating html tags directly

    htmltools::tags$ul(
      purrr::map(vec, htmltools::tags$li)
    )
    
    • a
    • b
    • c
    • d
    Rmd example
    ---
    title: "Title"
    output: md_document
    ---
    
    This vector can be transform in bullet list
    
    ```{r}
    vec <- letters[1:4]
    ```
    
    by generating markdown string
    
    ```{r, results='asis'}
    glue::glue("* {vec}")
    ```
    
    by generating html tags directly
    ```{r}
    htmltools::tags$ul(
      purrr::map(vec, htmltools::tags$li)
    )
    ```
    ---
    title: "Title"
    output: md_document
    ---
    
    This vector can be transform in bullet list
    
    ```{r}
    vec <- letters[1:4]
    ```
    
    by generating markdown string
    
    ```{r, results='asis'}
    glue::glue("* {vec}")
    ```
    
    by generating html tags directly
    ```{r}
    htmltools::tags$ul(
      purrr::map(vec, htmltools::tags$li)
    )
    ```
    
    5 Likes

    pander works perfectly!
    I've used it for analysis output, but never lists.

    1 Like

    This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.