Skip to content

Commit

Permalink
Tests, bug fixes, and documentation
Browse files Browse the repository at this point in the history
- Add rudimentary tests for elements
- Fix check_extension_arg not using valid_inputs parameter
- Documentation for the `with` family of functions
- Dummy readme.md
  • Loading branch information
ElianHugh committed Oct 17, 2023
1 parent 8d03ee7 commit 65d9149
Show file tree
Hide file tree
Showing 15 changed files with 207 additions and 178 deletions.
8 changes: 4 additions & 4 deletions R/elements.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
#' @family elements
#' @export
div <- function(..., attr = NULL) {
out <- "\n\n:::{%s}\n\n%s\n\n:::\n"
rlang::check_dots_unnamed()

out <- "\n\n:::{%s}\n\n%s\n\n:::\n"
args <- rlang::dots_list(...)
attr <- attr %||% "" |>
paste0(collapse = " ")
content <- args |>
unname() |>
paste0(collapse = "\n\n")

structure(
Expand All @@ -43,13 +43,13 @@ div <- function(..., attr = NULL) {
#' @family elements
#' @export
span <- function(..., attr = NULL) {
out <- "[%s]{%s}"
rlang::check_dots_unnamed()

out <- "[%s]{%s}"
args <- rlang::dots_list(...)
attr <- attr %||% "" |>
paste0(collapse = " ")
content <- args |>
unname() |>
paste0(collapse = " ")

structure(
Expand Down
2 changes: 1 addition & 1 deletion R/errors.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
check_extension_arg <- function(extension, valid_inputs) {
if (!is.null(extension)) {
extension %in% c("left", "right") || rlang::abort(
extension %in% valid_inputs || rlang::abort(
message = c(
sprintf("extension argument must be any of: NULL, %s.", paste0(valid_inputs, collapse = ", ")),
x = sprintf("supplied extension value: `%s`", extension),
Expand Down
15 changes: 6 additions & 9 deletions R/quartools-package.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#' quartools: programmatic element creation
#'
#' This package allows for the creation of quarto markdown via R function calls.
#'
#' @section
#'
#' todo
#'
#' @keywords internal
#' @importFrom rlang %||%
"_PACKAGE"


## usethis namespace: start
#' @importFrom rlang %||%
## usethis namespace: end
NULL
47 changes: 15 additions & 32 deletions R/with.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
#' TODO
#' Temporarily modify page layout
#' @description
#' TODO
#' @param ... todo
#' @param outset todo
#' @param extension todo
#' Create a div block that modifies the current quarto layout column temporarily.
#'
#' See [the Quarto documentation for a full list
#' of available extension options](https://quarto.org/docs/authoring/article-layout.html#available-columns).
#' @param ... arguments to pass to [quartools::div]
#' @param outset should the outset affix be applied to the column class?
#' @param extension affix class to apply to column class
#' @export
#' @family page layout functions
#' @examples
#' with_body_column("Hello world!")
#' @rdname page-layout
with_body_column <- function(..., outset = FALSE, extension = NULL) {
check_extension_arg(extension, c("left", "right"))
cls <- ".column-body%s%s"
Expand All @@ -19,14 +24,8 @@ with_body_column <- function(..., outset = FALSE, extension = NULL) {
)
}

#' TODO
#' @description
#' TODO
#' @param ... todo
#' @param outset todo
#' @param extension todo
#' @export
#' @family page layout functions
#' @rdname page-layout
with_page_column <- function(..., extension = NULL) {
check_extension_arg(extension, c("left", "right"))
cls <- ".column-page%s"
Expand All @@ -39,14 +38,8 @@ with_page_column <- function(..., extension = NULL) {
)
}

#' TODO
#' @description
#' TODO
#' @param ... todo
#' @param outset todo
#' @param extension todo
#' @export
#' @family page layout functions
#' @rdname page-layout
with_screen_inset_column <- function(..., extension = NULL) {
check_extension_arg(extension, c("left", "right", "shaded"))
cls <- ".column-screen-inset%s"
Expand All @@ -59,14 +52,8 @@ with_screen_inset_column <- function(..., extension = NULL) {
)
}

#' TODO
#' @description
#' TODO
#' @param ... todo
#' @param outset todo
#' @param extension todo
#' @export
#' @family page layout functions
#' @rdname page-layout
with_screen_column <- function(..., extension = NULL) {
check_extension_arg(extension, c("left", "right"))
cls <- ".column-screen%s"
Expand All @@ -79,12 +66,8 @@ with_screen_column <- function(..., extension = NULL) {
)
}

#' TODO
#' @description
#' TODO
#' @param ... todo
#' @export
#' @family page layout functions
#' @rdname page-layout
with_margin_column <- function(...) {
div(..., attr = ".column-margin")
}
55 changes: 55 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
output: github_document
---

<!-- README.md is generated from README.Rmd. Please edit that file -->

```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```

# quartools

<!-- badges: start -->
<!-- badges: end -->

The goal of quartools is to ...

## Installation

You can install the development version of quartools from [GitHub](https://github.com/) with:

``` r
# install.packages("devtools")
devtools::install_github("ElianHugh/quartools")
```

## Example

This is a basic example which shows you how to solve a common problem:

```{r example}
library(quartools)
## basic example code
```

What is special about using `README.Rmd` instead of just `README.md`? You can include R chunks like so:

```{r cars}
summary(cars)
```

You'll still need to render `README.Rmd` regularly, to keep `README.md` up-to-date. `devtools::build_readme()` is handy for this.

You can also embed plots, for example:

```{r pressure, echo = FALSE}
plot(pressure)
```

In that case, don't forget to commit and push the resulting figure files, so they display on GitHub and CRAN.
52 changes: 52 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->

# quartools

<!-- badges: start -->
<!-- badges: end -->

The goal of quartools is to …

## Installation

You can install the development version of quartools from
[GitHub](https://github.com/) with:

``` r
# install.packages("devtools")
devtools::install_github("ElianHugh/quartools")
```

## Example

This is a basic example which shows you how to solve a common problem:

``` r
library(quartools)
## basic example code
```

What is special about using `README.Rmd` instead of just `README.md`?
You can include R chunks like so:

``` r
summary(cars)
#> speed dist
#> Min. : 4.0 Min. : 2.00
#> 1st Qu.:12.0 1st Qu.: 26.00
#> Median :15.0 Median : 36.00
#> Mean :15.4 Mean : 42.98
#> 3rd Qu.:19.0 3rd Qu.: 56.00
#> Max. :25.0 Max. :120.00
```

You’ll still need to render `README.Rmd` regularly, to keep `README.md`
up-to-date. `devtools::build_readme()` is handy for this.

You can also embed plots, for example:

<img src="man/figures/README-pressure-1.png" width="100%" />

In that case, don’t forget to commit and push the resulting figure
files, so they display on GitHub and CRAN.
Binary file modified man/figures/README-pressure-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions man/page-layout.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions man/quartools-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 0 additions & 26 deletions man/with_body_column.Rd

This file was deleted.

22 changes: 0 additions & 22 deletions man/with_margin_column.Rd

This file was deleted.

26 changes: 0 additions & 26 deletions man/with_page_column.Rd

This file was deleted.

Loading

0 comments on commit 65d9149

Please sign in to comment.