You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pkgpurl facilitates R package authoring using a literate programming approach. The main idea behind this is to write all of the R source code in R Markdown files (`Rmd/*.Rmd`), which allows the actual code to be freely mixed with explanatory and supplementary information in expressive Markdown format. The main object of pkgpurl is to provide a standardized way to compile the bare `.R` files from the prose-enhanced and thus more human-oriented `.Rmd` files.
@@ -21,29 +23,29 @@ It is especially powerful in combination with the [Visual R Markdown](https://rs
21
23
22
24
The relevant editor options which adjust the canonical Markdown generation can either be set
23
25
24
-
-[per `.Rmd` file](https://rstudio.github.io/visual-markdown-editing/#/markdown?id=writer-options), e.g.
26
+
-[per `.Rmd` file](https://rstudio.github.io/visual-markdown-editing/#/markdown?id=writer-options), e.g.
25
27
26
-
```rmd
27
-
---
28
-
editor_options:
29
-
markdown:
30
-
wrap: 160
31
-
references:
32
-
location: section
33
-
canonical: true
34
-
---
35
-
```
28
+
```rmd
29
+
---
30
+
editor_options:
31
+
markdown:
32
+
wrap: 160
33
+
references:
34
+
location: section
35
+
canonical: true
36
+
---
37
+
```
36
38
37
-
-or [per project](https://rstudio.github.io/visual-markdown-editing/#/options?id=project-options) in the usual `PACKAGE_NAME.Rproj` file, e.g.
39
+
- or [per project](https://rstudio.github.io/visual-markdown-editing/#/options?id=project-options) in the usual `PACKAGE_NAME.Rproj` file, e.g.
38
40
39
-
```ini
40
-
MarkdownWrap: Column
41
-
MarkdownWrapAtColumn: 160
42
-
MarkdownReferences: Section
43
-
MarkdownCanonical: Yes
44
-
```
41
+
```ini
42
+
MarkdownWrap: Column
43
+
MarkdownWrapAtColumn: 160
44
+
MarkdownReferences: Section
45
+
MarkdownCanonical: Yes
46
+
```
45
47
46
-
(I’d recommend to set them *per project*, so they apply to the whole package including any `.Rmd` vignettes.)
48
+
(I’d recommend to set them *per project*, so they apply to the whole package including any `.Rmd` vignettes.)
47
49
48
50
</details>
49
51
<details>
@@ -179,45 +181,43 @@ All the `.gen.R` suffixed R source code found under [`R/`](https://gitlab.com/rp
179
181
180
182
### Coding style
181
183
182
-
This package borrows a lot of the [Tidyverse](https://www.tidyverse.org/) design philosophies. The R code adheres to the principles specified in the [Tidyverse Design Guide](https://principles.tidyverse.org/) wherever possible and is formatted according to the [Tidyverse Style Guide](https://style.tidyverse.org/) (TSG) with the following exceptions:
184
+
This package borrows a lot of the [Tidyverse](https://www.tidyverse.org/) design philosophies. The R code is guided by the [Tidy design principles](https://design.tidyverse.org/) and is formatted according to the [Tidyverse Style Guide](https://style.tidyverse.org/) (TSG) with the following exceptions:
183
185
184
-
-Line width is limited to **160 characters**, double the [limit proposed by the TSG](https://style.tidyverse.org/syntax.html#long-lines) (80 characters is ridiculously little given today’s high-resolution wide screen monitors).
186
+
- Line width is limited to **160 characters**, double the [limit proposed by the TSG](https://style.tidyverse.org/syntax.html#long-lines) (80 characters is ridiculously little given today’s high-resolution wide screen monitors).
185
187
186
-
Furthermore, the preferred style for breaking long lines differs. Instead of wrapping directly after an expression’s opening bracket as [suggested by the TSG](https://style.tidyverse.org/syntax.html#long-lines), we prefer two fewer line breaks and indent subsequent lines within the expression by its opening bracket:
188
+
Furthermore, the preferred style for breaking long lines differs. Instead of wrapping directly after an expression’s opening bracket as [suggested by the TSG](https://style.tidyverse.org/syntax.html#long-lines), we prefer two fewer line breaks and indent subsequent lines within the expression by its opening bracket:
- Usage of [R’s right-hand assignment operator `->`](https://rdrr.io/r/base/assignOps.html) is not allowed[^6].
207
209
208
-
-Rsourcecodeis*not*splitoverseveralfilesas [suggestedbytheTSG](https://style.tidyverse.org/package-files.html) butinstead is (asfaraspossible) keptinthesinglefile [`Rmd/pkgpurl.Rmd`](https://gitlab.com/rpkg.dev/pkgpurl/-/tree/master/Rmd/pkgpurl.Rmd) whichiswell-structuredthankstoits [Markdownsupport](#r-markdown-format).
210
+
- R source code is *not* split over several files as [suggested by the TSG](https://style.tidyverse.org/package-files.html) but instead is (as far as possible) kept in the single file [`Rmd/pkgpurl.Rmd`](https://gitlab.com/rpkg.dev/pkgpurl/-/tree/master/Rmd/pkgpurl.Rmd) which is well-structured thanks to its [Markdown support](#r-markdown-format).
209
211
210
212
As far as possible, these deviations from the TSG plus some additional restrictions are formally specified in [`pkgpurl::default_linters`](https://pkgpurl.rpkg.dev/reference/default_linters), which is (by default) used in [`pkgpurl::lint_rmd()`](https://pkgpurl.rpkg.dev/reference/lint_rmd), which in turn is the recommended way to lint this package.
211
213
212
-
---
213
-
214
214
[^1]: Actually, you could write anything you like in any syntax outside of R code chunks as long as you don’t mind the file to be *knittable* (which it doesn’t have to be).
215
215
216
216
[^2]: It basically sends the (R) Markdown file on a “Pandoc round trip” on every file save.
217
217
218
218
[^3]: I personally recommend to use the shortcut <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>V</kbd> since it’s not occupied yet by any of the predefined [RStudio shortcuts](https://support.posit.co/hc/en-us/articles/200711853-Keyboard-Shortcuts).
[^4]: The very idea to leverage the R Markdown format to author R packages was originally proposed by Yihui Xie. See his excellent [blog post](https://yihui.org/rlp/) for his point of view on the advantages of literate programming techniques and some practical examples. Note that using `pkgpurl::purl_rmd()` is a less cumbersome alternative to the Makefile approach outlined by him.
221
221
222
222
[^5]: The TSG [explicitly instructs to avoid this operator](https://style.tidyverse.org/pipes.html#assignment-2) – presumably because it’s relatively unknown and therefore might be confused with the forward pipe operator `%>%` when skimming code only briefly. I don’t consider this to be an actual issue since there aren’t many sensible usage patterns of `%>%` at the beginning of a pipe sequence inside a function – I can only think of creating side effects and relying on [R’s implicit return of the last evaluated expression](https://rdrr.io/r/base/function.html). Therefore – and because I really like the `%<>%` operator – it’s usage is welcome.
0 commit comments