Skip to contents

Does all code in the .Rmd end up in the R package?

No, a code chunk is only sent to the R/ file of the R package if it starts with #'. If testthat::test_that() is used in a code chunk, that chunk will be added to the package as a unit test. For an example of both of these, see create-rhello.Rmd and the resulting package. If you want a code chunk sent to your R package that doesn’t start with the roxygen2-style #', you can instead add the explicit location of where it should go using a chunk option of the form send_to="R/myfile.R". You can send code from multiple code chunks to the same file if you like.

Do I have to learn special syntax to use litr?

No. The .Rmd file that generates an R package with litr uses exactly the same syntax as a regular .Rmd file. You will need to use roxygen2 for documenting your functions; however, you would probably be using roxygen2 even if you weren’t using litr.

How does the litr .Rmd relate to a vignette?

A vignette serves a very different purpose from the .Rmd file you use in litr. The goal of a vignette is to show potential users of your package how they can use it. By contrast, the litr .Rmd file is a document that is the source code, presented in a way that is optimized for human readability. The audience of this file is your future self or anyone who may eventually wish to modify your R package or understand its inner workings. Typical users of your package will not need to see this document.

For large packages, can I write my package across multiple .Rmd files?

Yes! You can use bookdown to define your R package across multiple .Rmd files. This leads to a nice looking online book with multiple chapters. When you render the book all .Rmd files are run in a single environment, so it behaves in the same way as if you had one enormous .Rmd file. Here’s an example. The easiest way to get started is to work from template using litr::draft_bookdown().

Can I include a README for my package?

Yes! You can do so using the function litr::add_readme(). See the template create-withpkgdown.Rmd for an example of how this works.

Can I include vignettes in my package?

Yes! You can do so using the function litr::add_vignettes(). See the template create-withpkgdown.Rmd for an example of how this works.

Can I make a pkgdown site for my package?

Yes! See the template create-withpkgdown.Rmd for an example of how this works.

Is it true that literate programming won an Academy Award?

Almost, but not quite. Donald Knuth was personally thanked in an Academy Award acceptance speech for developing literate programming. See Kristen Bell and Michael B. Jordan clapping for literate programming here.

Did you use litr to write litr?

Yes! Version 0.0.1 of litr was written in the traditional way (since litr didn’t yet exist…). But thereafter, version n+1 of litr was written using version n of litr. For more on the creation of litr, see here. Or if you’re really interested, have a look at the literate programming bookdown that defines the litr.