Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jacobbien/litr-project
Writing R Packages with Literate Programming
https://github.com/jacobbien/litr-project
knitr literate-programming r r-package rmarkdown
Last synced: 3 months ago
JSON representation
Writing R Packages with Literate Programming
- Host: GitHub
- URL: https://github.com/jacobbien/litr-project
- Owner: jacobbien
- License: other
- Created: 2022-04-20T05:08:03.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-05T23:31:50.000Z (4 months ago)
- Last Synced: 2024-07-06T03:18:05.877Z (4 months ago)
- Topics: knitr, literate-programming, r, r-package, rmarkdown
- Language: HTML
- Homepage: https://jacobbien.github.io/litr-project/
- Size: 14.2 MB
- Stars: 36
- Watchers: 3
- Forks: 3
- Open Issues: 8
-
Metadata Files:
- Readme: README.Rmd
- Contributing: CONTRIBUTING.md
Awesome Lists containing this project
- jimsghstars - jacobbien/litr-project - Writing R Packages with Literate Programming (HTML)
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
eval = FALSE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```# Creating `litr`
**Note:** If you are looking to use the `litr` package, please visit the `litr` website [here](https://jacobbien.github.io/litr-project/), where you'll be able to learn about the package. If you are interested in how `litr` is made, you are in the right place.
## Background
The `litr` R package allows one to write R packages using literate programming. The developers of `litr` are believers in literate programming and so, quite naturally, want to use literate programming to develop `litr`. For obvious reasons, we couldn't use `litr` before it existed. So we wrote the initial viable version in a standard, non-literate way and released this as [v0.0.1](https://github.com/jacobbien/litr-project/releases/tag/v0.0.1). We can think of this as the "base case." This is the last version that is written in the traditional way. Every subsequent version of `litr` will be generated using the previous version of `litr`. In particular, v0.0.2 of `litr` is functionally equivalent to v0.0.1, but the package is defined in a generating .Rmd file; a call to v0.0.1's `litr::render()` outputs the `litr` package v0.0.2. This all might sound complicated, but one can think of this as how developers of an operating system probably write their code on a computer that is running the previous stable version of the operating system.
## How to generate a new version of `litr` using the previous release
To create a new version of `litr`, we first install the latest release, then make any desired changes to `create-litr.Rmd` and then use the installed version's `litr::render()` to create the new version:
```{r}
remotes::install_github("jacobbien/litr-project@*release", subdir = "litr")
litr::render("create-litr/index.Rmd")
fs::dir_copy("create-litr/_book", "docs/create", overwrite = TRUE)
fs::dir_delete("create-litr/_book")
```In the above code, `@*release` stands for the latest release. For example, at the time of creating version `0.0.2`, this would be `v0.0.1`.
This will generate the new version of `litr` along with [this bookdown](https://jacobbien.github.io/litr-project/create/). From there, you can build/install as you would for any other package. For checking the package, use
```{r}
devtools::check("litr", document = FALSE)
```The `document = FALSE` prevents `devtools` from running its version of `document()` internally, which would overwrite the modifications that `litr::document()` has made.
For more notes on contributing to `litr`, please see [CONTRIBUTING.md](CONTRIBUTING.md).