rr-box

using klmr box::use in an rmarkdown document


Can anyone give me an example to add libraries and local functions with the klmr::box package in a rmarkdown document?

I am aware of their use in Rhino´s framework, but I feel a bit confused where can I declare modules and libraries in a YAML + Rmarkdown file.


Solution

  • The way is to remember he location of the .Rmd file. The difference with the package here::here is that it does not go backwards from the .Rmd location. box yes, using .. in fromt of module's statements.

    ```{r setup, include=FALSE, warning=FALSE, echo=FALSE}
    box::use(
      r/core[...],
      dplyr[
        `%>%`, mutate, across, rename, case_when, if_else,
        select, filter, group_by, left_join, summarise, pull, arrange, desc,
        n, n_distinct
      ],
      tidyr[pivot_wider, fill, complete, nesting, replace_na],
      glue[glue],
    )
    
    box::use(../data/constants)
    box::use(../logic/some_function_in_project)
    box::use(../logic/dependencies)
    
    # example of alias
    kable_formating <- dependencies$kable_formating$kable_formating
    ```
    

    In their invocation, keep one eye in the relative locations: