Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ElianHugh committed Oct 16, 2023
0 parents commit c12d162
Show file tree
Hide file tree
Showing 17 changed files with 3,772 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
^quartools\.Rproj$
^\.Rproj\.user$
^\.github$
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.html
29 changes: 29 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples
# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help
on:
push:
branches: [main, master]
pull_request:
branches: [main, master]

name: R-CMD-check

jobs:
R-CMD-check:
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}
R_KEEP_PKG_SOURCE: yes
steps:
- uses: actions/checkout@v3

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true

- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::rcmdcheck
needs: check

- uses: r-lib/actions/check-r-package@v2
49 changes: 49 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# History files
.Rhistory
.Rapp.history

# Session Data files
.RData
.RDataTmp

# User-specific files
.Ruserdata

# Example code in package build process
*-Ex.R

# Output files from R CMD build
/*.tar.gz

# Output files from R CMD check
/*.Rcheck/

# RStudio files
.Rproj.user/

# produced vignettes
vignettes/*.html
vignettes/*.pdf

# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3
.httr-oauth

# knitr and R markdown default cache directories
*_cache/
/cache/

# Temporary files created by R markdown
*.utf8.md
*.knit.md

# R Environment Variables
.Renviron

# pkgdown site
docs/

# translation temp files
po/*~

# RStudio Connect folder
rsconnect/
9 changes: 9 additions & 0 deletions .lintr
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
linters: with_defaults(
line_length_linter(120),
implicit_integer_linter(),
indentation_linter(indent = 4L),
object_usage_linter = NULL,
object_name_linter = NULL
)
exclusions: list("man/", "inst/", "src/", ".vscode/", ".Rproj.user/")
encoding: "UTF-8"
14 changes: 14 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Package: quartools
Title: Programmatic Element Creation For Quarto Documents
Version: 0.0.0.9000
Authors@R:
person("Elian", "Thiele-Evans", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-8008-3165"))
Description: What the package does (one paragraph).
License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a
license
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3.9000
Imports:
rlang
8 changes: 8 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Generated by roxygen2: do not edit by hand

export(as_markdown)
export(div)
export(mdapply)
export(span)
export(with_body_column)
importFrom(rlang,"%||%")
37 changes: 37 additions & 0 deletions R/elements.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#' Create a quarto div element
#' @description todo
#' @importFrom rlang %||%
#' @export
div <- function(..., attr = NULL) {
out <- "\n\n:::{%s}\n\n%s\n\n:::\n"

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

structure(
sprintf(out, attr, content),
class = "knit_asis"
)
}

#' Create a quarto span element
#' @description todo
#' @export
span <- function(..., attr = NULL) {
out <- "[%s]{%s}"

args <- rlang::dots_list(...)
attr <- attr %||% ""
content <- args |>
unname() |>
paste0(collapse = " ")

structure(
sprintf(out, content, attr),
class = "knit_asis"
)
}

27 changes: 27 additions & 0 deletions R/helper.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#' @export
as_markdown <- function(x) {
structure(
paste0(x, collapse = ""),
class = "knit_asis"
)
}

#' Markdown Apply
#' @description
#' Generate markdown by applying a function to a list of elements.
#' The function is expected to return valid markdown content.
#' @param x a vector, expression, or any object coercible to a list
#' @param fun function to apply to each element of x
#' @param ... optional arguments to fun
#' @examples
#' my_list <- list("A", "B", "C")
#' mdapply(my_list, div)
#' @export
#' @seealso [base::lapply]
mdapply <- function(x, fun, ...) {
res <- do.call(
lapply,
args = list(X = x, FUN = fun, ... = ...)
)
as_markdown(res)
}
8 changes: 8 additions & 0 deletions R/with.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#' @export
with_body_column <- function(..., outset = FALSE) {
if (isTRUE(outset)) {
div(..., attr = ".column-body-outset")
} else {
div(..., attr = ".column-body")
}
}
11 changes: 11 additions & 0 deletions man/div.Rd

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

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

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

11 changes: 11 additions & 0 deletions man/span.Rd

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

17 changes: 17 additions & 0 deletions quartools.Rproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Version: 1.0

RestoreWorkspace: No
SaveWorkspace: No
AlwaysSaveHistory: Default

EnableCodeIndexing: Yes
Encoding: UTF-8

AutoAppendNewline: Yes
StripTrailingWhitespace: Yes
LineEndingConversion: Posix

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace
Loading

0 comments on commit c12d162

Please sign in to comment.