boB Rudis
4 years ago
27 changed files with 972 additions and 15 deletions
@ -0,0 +1,2 @@ |
|||
YEAR: 2020 |
|||
COPYRIGHT HOLDER: Bob Rudis |
@ -0,0 +1,21 @@ |
|||
# MIT License |
|||
|
|||
Copyright (c) 2020 Bob Rudis |
|||
|
|||
Permission is hereby granted, free of charge, to any person obtaining a copy |
|||
of this software and associated documentation files (the "Software"), to deal |
|||
in the Software without restriction, including without limitation the rights |
|||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|||
copies of the Software, and to permit persons to whom the Software is |
|||
furnished to do so, subject to the following conditions: |
|||
|
|||
The above copyright notice and this permission notice shall be included in all |
|||
copies or substantial portions of the Software. |
|||
|
|||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|||
SOFTWARE. |
@ -1,4 +1,16 @@ |
|||
# Generated by roxygen2: do not edit by hand |
|||
|
|||
import(httr) |
|||
importFrom(jsonlite,fromJSON) |
|||
S3method(print,prince) |
|||
export("%>%") |
|||
export(pr_add_css_file) |
|||
export(pr_add_css_rules) |
|||
export(pr_add_sources) |
|||
export(pr_enable_js) |
|||
export(pr_raster) |
|||
export(pr_render) |
|||
export(pr_set_input_format) |
|||
export(pr_set_pdf_metadata) |
|||
export(prince) |
|||
import(sys) |
|||
importFrom(magrittr,"%>%") |
|||
importFrom(rmarkdown,render) |
|||
|
@ -0,0 +1,89 @@ |
|||
#' Set input format |
|||
#' |
|||
#' @param p Prince object |
|||
#' @param fmt one of `auto`, `xml`, or `html`. Defaults to `auto`. |
|||
#' @export |
|||
pr_set_input_format <- function(p, fmt = c("auto", "xml", "html")) { |
|||
fmt <- match.arg(fmt[1], c("auto", "xml", "html")) |
|||
p$input_format <- fmt |
|||
invisible(p) |
|||
} |
|||
|
|||
|
|||
#' Enable JavaScript processing |
|||
#' |
|||
#' @param p Prince object |
|||
#' @export |
|||
pr_enable_js <- function(p) { |
|||
p$javascript <- TRUE |
|||
invisible(p) |
|||
} |
|||
|
|||
#' Add HTML sources to be processed |
|||
#' |
|||
#' @param p Prince object |
|||
#' @param source_paths character vector of HTML/XML source paths/URLs. NOTE: |
|||
#' [path.expand()] will _not_ be run. You are responsible for ensuring |
|||
#' Prince can find each specified source. |
|||
#' @export |
|||
#' @examples |
|||
#' if (interactive()) { |
|||
#' |
|||
#' # read from a URL |
|||
#' |
|||
#' prince() %>% |
|||
#' pr_enable_js() %>% |
|||
#' pr_add_sources("http://css4.pub/2018/toc") %>% |
|||
#' pr_render(tempfile(fileext = ".pdf", open = TRUE) |
|||
#' |
|||
#' } |
|||
pr_add_sources <- function(p, source_paths) { |
|||
p$source_files <- c(p$source_files, source_paths) |
|||
invisible(p) |
|||
} |
|||
|
|||
#' Add CSS files to be included during processing |
|||
#' |
|||
#' @param p Prince object |
|||
#' @param css_paths character vector of CSS source paths/URLs. NOTE: |
|||
#' [path.expand()] will _not_ be run. You are responsible for ensuring |
|||
#' Prince can find each specified source. |
|||
#' @export |
|||
pr_add_css_file <- function(p, css_paths) { |
|||
p$css_files <- c(p$css_files, css_paths) |
|||
invisible(p) |
|||
} |
|||
|
|||
#' Add "raw" CSS rules |
|||
#' |
|||
#' @param p Prince object |
|||
#' @param rule character vector of CSS rules. These will be combined into |
|||
#' a temporary CSS file and included during the render. |
|||
#' @export |
|||
pr_add_css_rules <- function(p, css_rules) { |
|||
p$css_rules <- c(p$css_rules, css_rules) |
|||
invisible(p) |
|||
} |
|||
|
|||
#' Set PDF metadata |
|||
#' |
|||
#' @param p Prince object |
|||
#' @param title set document title |
|||
#' @param subject set document subject |
|||
#' @param author set document author |
|||
#' @param keywords set document keywords |
|||
#' @param creator set document creator |
|||
#' @export |
|||
pr_set_pdf_metadata <- function(p, title, subject, author, keywords, creator) { |
|||
|
|||
if (!"pdf_meta" %in% names(p)) p$pdf_meta <- list() |
|||
|
|||
if (!missing(title)) p$pdf_meta$title <- title[1] |
|||
if (!missing(subject)) p$pdf_meta$subject <- subject[1] |
|||
if (!missing(author)) p$pdf_meta$author <- author[1] |
|||
if (!missing(keywords)) p$pdf_meta$keywords <- keywords[1] |
|||
if (!missing(creator)) p$pdf_meta$creator <- creator[1] |
|||
|
|||
invisible(p) |
|||
|
|||
} |
@ -0,0 +1,72 @@ |
|||
#' Start a Prince processing chain |
|||
#' |
|||
#' @param path fully qualified path to Prince executable. Will attempt |
|||
#' to find it if no path is specified. |
|||
#' @return prince object |
|||
#' @export |
|||
#' @examples |
|||
#' #' if (interactive()) { |
|||
#' prince() %>% |
|||
#' pr_add_sources( |
|||
#' source_paths = c( |
|||
#' system.file("examples", "lab-report.html", package = "purplerain") |
|||
#' ) |
|||
#' ) %>% |
|||
#' pr_add_css_rules("body { font-family: sans-serif; }") %>% |
|||
#' pr_add_css_rules(c( |
|||
#' "h1, h2.subtitle{ text-align: center; }", |
|||
#' "h2.subtitle { font-size: 14pt; }" |
|||
#' )) %>% |
|||
#' pr_add_css_rules(" |
|||
#' #hello { |
|||
#' color: red; |
|||
#' text-align: center; |
|||
#' font-size: large; |
|||
#' font-style: italic; |
|||
#' font-family: serif; |
|||
#' }") %>% |
|||
#' pr_render(tempfile(fileext=".pdf"), open = TRUE) |
|||
#' } |
|||
prince <- function(path = Sys.which("prince")) { |
|||
|
|||
path <- path.expand(path) |
|||
|
|||
if (!file.exists(path)) { |
|||
stop( |
|||
"Prince executable not found. Please download Prince ", |
|||
"(https://www.princexml.com/download/) for your platform ", |
|||
"and install it to use this package.", call.=FALSE |
|||
) |
|||
} |
|||
|
|||
res_v <- sys::exec_internal(path, "--version") |
|||
res_c <- sys::exec_internal(path, "--credits") |
|||
|
|||
list( |
|||
exec = path, |
|||
version = rawToChar(res_v$stdout), |
|||
credits = rawToChar(res_c$stdout), |
|||
source_files = c(), |
|||
css_files = c(), |
|||
css_rules = c(), |
|||
input_format = "auto", |
|||
javascript = FALSE |
|||
) -> out |
|||
|
|||
class(out) <- c("prince", "list") |
|||
|
|||
invisible(out) |
|||
|
|||
} |
|||
|
|||
#' @param x object |
|||
#' @param ... unused |
|||
#' @rdname prince |
|||
#' @export |
|||
print.prince <- function(x, ...) { |
|||
|
|||
cat(x$version) |
|||
|
|||
invisible(x) |
|||
|
|||
} |
@ -1,9 +1,12 @@ |
|||
#' ... |
|||
#' |
|||
#' @md |
|||
#' Tools to Produce Publication-quality HTML and PDF Output via the Prince Utility |
|||
#' |
|||
#' Prince (<https://www.princexml.com/>) is a framework and toolchain that |
|||
#' enables the creation of publication-quality HTML and PDF output from XML or HTML |
|||
#' sources. Tools are provided to orchestrate document creation with Prince. |
|||
#' |
|||
#' @name purplerain |
|||
#' @keywords internal |
|||
#' @author Bob Rudis (bob@@rud.is) |
|||
#' @import httr |
|||
#' @importFrom jsonlite fromJSON |
|||
#' @import sys |
|||
#' @importFrom rmarkdown render |
|||
"_PACKAGE" |
|||
|
@ -0,0 +1,68 @@ |
|||
#' Render a Prince chain to raster output |
|||
#' |
|||
#' @param p Prince object |
|||
#' @param output_template location and template for output file. NOTE: |
|||
#' [path.expand()] will _not_ be run. See |
|||
#' [Raster Output Options](https://www.princexml.com/doc/command-line/#raster-output-options) |
|||
#' @param format if `auto` then Prince guesses based on file extension in |
|||
#' `output_template`, otherwise specify `png` or `jpeg`. |
|||
#' @export |
|||
#' @examples |
|||
#' if (interactive()) { |
|||
#' prince() %>% |
|||
#' pr_add_sources( |
|||
#' source_paths = c( |
|||
#' system.file("examples", "lab-report.html", package = "purplerain") |
|||
#' ) |
|||
#' ) %>% |
|||
#' pr_add_css_rules("body { font-family: sans-serif; }") %>% |
|||
#' pr_add_css_rules(c( |
|||
#' "h1, h2.subtitle{ text-align: center; }", |
|||
#' "h2.subtitle { font-size: 14pt; }" |
|||
#' )) %>% |
|||
#' pr_add_css_rules(" |
|||
#' #hello { |
|||
#' color: red; |
|||
#' text-align: center; |
|||
#' font-size: large; |
|||
#' font-style: italic; |
|||
#' font-family: serif; |
|||
#' }") %>% |
|||
#' pr_raster(tempfile(pattern = "ex-%02d", fileext=".png")) |
|||
#' } |
|||
pr_raster <- function(pr, output_template, format = c("auto", "png", "jpeg")) { |
|||
|
|||
if (length(pr$source_files) == 0) { |
|||
stop("No input source files specified.", call.=FALSE) |
|||
} |
|||
|
|||
format <- match.arg(format[1], c("auto", "png", "jpeg")) |
|||
|
|||
args <- sprintf("--raster-output=%s", output_template) |
|||
args <- c(args, sprintf("--raster-format=%s", format)) |
|||
|
|||
if (length(pr$input_format) > 0) args <- c(sprintf("--input=%s", pr$input_format), args) |
|||
|
|||
if (isTRUE(pr$javascript)) args <- c("--javascript", args) |
|||
|
|||
if (length(pr$css_rules) > 0) { |
|||
tf <- tempfile(fileext = ".css") |
|||
on.exit(unlink(tf), add = TRUE) |
|||
writeLines(pr$css_rules, tf) |
|||
pr$css_files <- c(pr$css_files, tf) |
|||
} |
|||
|
|||
if (length(pr$css_files) > 0) args <- c(sprintf("--style=%s", pr$css_files), args) |
|||
|
|||
args <- c(args, pr$source_files) |
|||
|
|||
# message(pr$exec, " ", paste0(args, collapse = " ")) |
|||
|
|||
sys::exec_internal( |
|||
cmd = pr$exec, |
|||
args = args |
|||
) -> res |
|||
|
|||
invisible(res) |
|||
|
|||
} |
@ -0,0 +1,63 @@ |
|||
#' Render a Prince chain |
|||
#' |
|||
#' @param p Prince object |
|||
#' @param output_file place to put the output PDF (including filename). NOTE: |
|||
#' [path.expand()] will _not_ be run. |
|||
#' @param open open the output file (in the system default viewer) after rendering? |
|||
#' Default: `FALSE`. |
|||
#' @export |
|||
#' @examples |
|||
#' #' if (interactive()) { |
|||
#' rmarkdown::render( |
|||
#' input = system.file("examples", "r-markdown.Rmd", package = "purplerain"), |
|||
#' output_file = "/tmp/example.html", |
|||
#' quiet = TRUE |
|||
#' ) |
|||
#' |
|||
#' prince() %>% |
|||
#' pr_add_sources("/tmp/example.html") %>% |
|||
#' pr_render("/tmp/r-markdown.pdf", TRUE) |
|||
#' |
|||
#' prince() %>% |
|||
#' pr_add_sources("/tmp/example.html") %>% |
|||
#' pr_raster("/tmp/r-markdown-%02d.png") |
|||
#' } |
|||
pr_render <- function(pr, output_file, open=FALSE) { |
|||
|
|||
if (length(pr$source_files) == 0) { |
|||
stop("No input source files specified.", call.=FALSE) |
|||
} |
|||
|
|||
args <- sprintf("--output=%s", output_file) |
|||
|
|||
if (length(pr$input_format) > 0) args <- c(sprintf("--input=%s", pr$input_format), args) |
|||
|
|||
if (isTRUE(pr$javascript)) args <- c("--javascript", args) |
|||
|
|||
if (length(pr$css_rules) > 0) { |
|||
tf <- tempfile(fileext = ".css") |
|||
on.exit(unlink(tf), add = TRUE) |
|||
writeLines(pr$css_rules, tf) |
|||
pr$css_files <- c(pr$css_files, tf) |
|||
} |
|||
|
|||
if (length(pr$css_files) > 0) args <- c(sprintf("--style=%s", pr$css_files), args) |
|||
|
|||
args <- c(args, pr$source_files) |
|||
|
|||
# message(pr$exec, " ", paste0(args, collapse = " ")) |
|||
|
|||
sys::exec_internal( |
|||
cmd = pr$exec, |
|||
args = args |
|||
) -> res |
|||
|
|||
if (res$status != 0) { |
|||
warning(rawToChar(res$stderr), call.=FALSE) |
|||
} else { |
|||
if (open) .open_file(output_file) |
|||
} |
|||
|
|||
invisible(res) |
|||
|
|||
} |
@ -0,0 +1,11 @@ |
|||
#' Pipe operator |
|||
#' |
|||
#' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. |
|||
#' |
|||
#' @name %>% |
|||
#' @rdname pipe |
|||
#' @keywords internal |
|||
#' @export |
|||
#' @importFrom magrittr %>% |
|||
#' @usage lhs \%>\% rhs |
|||
NULL |
@ -0,0 +1,26 @@ |
|||
.open_file <- function(x) { |
|||
|
|||
stopifnot( |
|||
"No file to open." = (!missing(x)), |
|||
"File not found." = (file.exists(x)) |
|||
) |
|||
|
|||
if (missing(x)) stop('No file to open!', call.=FALSE) |
|||
|
|||
if (grepl('win', .Platform$OS.type, ignore.case = TRUE)) { # Ugh, Windows |
|||
shell.exec(f) |
|||
} else { |
|||
if (grepl('darwin', version$os, ignore.case = TRUE)) { # macOS |
|||
sys::exec_internal( |
|||
cmd = "open", |
|||
args = x |
|||
) |
|||
} else { # linuxs |
|||
sys::exec_internal( |
|||
cmd = Sys.which("xdg-open"), |
|||
args = x |
|||
) |
|||
} |
|||
} |
|||
|
|||
} |
@ -0,0 +1,150 @@ |
|||
|
|||
[![Project Status: Active – The project has reached a stable, usable |
|||
state and is being actively |
|||
developed.](https://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) |
|||
[![Signed |
|||
by](https://img.shields.io/badge/Keybase-Verified-brightgreen.svg)](https://keybase.io/hrbrmstr) |
|||
![Signed commit |
|||
%](https://img.shields.io/badge/Signed_Commits-100%25-lightgrey.svg) |
|||
[![Linux build |
|||
Status](https://travis-ci.org/hrbrmstr/purplerain.svg?branch=master)](https://travis-ci.org/hrbrmstr/purplerain) |
|||
![Minimal R |
|||
Version](https://img.shields.io/badge/R%3E%3D-3.6.0-blue.svg) |
|||
![License](https://img.shields.io/badge/License-MIT-blue.svg) |
|||
|
|||
# purplerain |
|||
|
|||
Tools to Produce Publication-quality HTML and PDF Output via the Prince |
|||
Utility |
|||
|
|||
## Description |
|||
|
|||
Prince (<https://www.princexml.com/>) is a framework and toolchain that |
|||
enables the creation of publication-quality HTML and PDF output from XML |
|||
or HTML sources. Tools are provided to orchestrate document creation |
|||
with Prince. |
|||
|
|||
## WIP |
|||
|
|||
This is package is in rapid development mode. The API will most |
|||
certainly change. |
|||
|
|||
## What’s Inside The Tin |
|||
|
|||
The following functions are implemented: |
|||
|
|||
- `pr_add_css_file`: Add CSS files to be included during processing |
|||
- `pr_add_css_rules`: Add “raw” CSS rules |
|||
- `pr_add_sources`: Add HTML sources to be processed |
|||
- `pr_enable_js`: Enable JavaScript processing |
|||
- `pr_raster`: Render a Prince chain to raster output |
|||
- `pr_render`: Render a Prince chain |
|||
- `pr_set_input_format`: Set input format |
|||
- `pr_set_pdf_metadata`: Set PDF metadata |
|||
- `prince`: Start a Prince processing chain |
|||
|
|||
## Installation |
|||
|
|||
``` r |
|||
remotes::install_git("https://git.rud.is/hrbrmstr/purplerain.git") |
|||
# or |
|||
remotes::install_git("https://git.sr.ht/~hrbrmstr/purplerain") |
|||
# or |
|||
remotes::install_gitlab("hrbrmstr/purplerain") |
|||
# or |
|||
remotes::install_bitbucket("hrbrmstr/purplerain") |
|||
``` |
|||
|
|||
NOTE: To use the ‘remotes’ install options you will need to have the |
|||
[{remotes} package](https://github.com/r-lib/remotes) installed. |
|||
|
|||
## Usage |
|||
|
|||
``` r |
|||
library(purplerain) |
|||
|
|||
# current version |
|||
packageVersion("purplerain") |
|||
## [1] '0.1.0' |
|||
``` |
|||
|
|||
### Render an HTML file to PDF with some extra/custom CSS rules |
|||
|
|||
``` r |
|||
prince() %>% |
|||
pr_add_sources( |
|||
source_paths = c( |
|||
system.file("examples", "lab-report.html", package = "purplerain") |
|||
) |
|||
) %>% |
|||
pr_add_css_rules("body { font-family: sans-serif; }") %>% |
|||
pr_add_css_rules(c( |
|||
"h1, h2.subtitle{ text-align: center; }", |
|||
"h2.subtitle { font-size: 14pt; }" |
|||
)) %>% |
|||
pr_add_css_rules(" |
|||
#hello { |
|||
color: red; |
|||
text-align: center; |
|||
font-size: large; |
|||
font-style: italic; |
|||
font-family: serif; |
|||
}") %>% |
|||
pr_render(tempfile(fileext=".pdf"), open = FALSE) |
|||
``` |
|||
|
|||
### Rasterize an HTML file to PNG with some extra/custom CSS rules |
|||
|
|||
``` r |
|||
prince() %>% |
|||
pr_add_sources( |
|||
source_paths = c( |
|||
system.file("examples", "lab-report.html", package = "purplerain") |
|||
) |
|||
) %>% |
|||
pr_add_css_rules("body { font-family: sans-serif; }") %>% |
|||
pr_add_css_rules(c( |
|||
"h1, h2.subtitle{ text-align: center; }", |
|||
"h2.subtitle { font-size: 14pt; }" |
|||
)) %>% |
|||
pr_add_css_rules(" |
|||
#hello { |
|||
color: red; |
|||
text-align: center; |
|||
font-size: large; |
|||
font-style: italic; |
|||
font-family: serif; |
|||
}") %>% |
|||
pr_raster(tempfile(pattern = "ex-%02d", fileext=".png")) |
|||
``` |
|||
|
|||
### Render an HTML file from an R Markdown file then render that result to PDF and rasterize it, too |
|||
|
|||
``` r |
|||
rmarkdown::render( |
|||
input = system.file("examples", "r-markdown.Rmd", package = "purplerain"), |
|||
output_file = "/tmp/example.html", |
|||
quiet = TRUE |
|||
) |
|||
|
|||
prince() %>% |
|||
pr_add_sources("/tmp/example.html") %>% |
|||
pr_render("/tmp/r-markdown.pdf", TRUE) |
|||
|
|||
prince() %>% |
|||
pr_add_sources("/tmp/example.html") %>% |
|||
pr_raster("/tmp/r-markdown-%02d.png") |
|||
``` |
|||
|
|||
## purplerain Metrics |
|||
|
|||
| Lang | \# Files | (%) | LoC | (%) | Blank lines | (%) | \# Lines | (%) | |
|||
| :--- | -------: | ---: | --: | --: | ----------: | ---: | -------: | ---: | |
|||
| R | 8 | 0.89 | 136 | 0.7 | 51 | 0.67 | 148 | 0.78 | |
|||
| Rmd | 1 | 0.11 | 57 | 0.3 | 25 | 0.33 | 41 | 0.22 | |
|||
|
|||
## Code of Conduct |
|||
|
|||
Please note that this project is released with a Contributor Code of |
|||
Conduct. By participating in this project you agree to abide by its |
|||
terms. |
@ -0,0 +1,72 @@ |
|||
<!DOCTYPE html> |
|||
<html lang="en"> |
|||
<head> |
|||
<title>Lab Report</title> |
|||
</head> |
|||
<body> |
|||
|
|||
<h1>Lab Report</h1> |
|||
<h2 class="subtitle">John Doe</h2> |
|||
|
|||
<h2>Aim</h2> |
|||
|
|||
<p> |
|||
This simple document aims to show just how easy it is to generate PDFs from |
|||
HTML+CSS using Prince. The document mostly uses Prince's built in styles |
|||
for HTML, but it also applies some custom styles. The custom styles: center |
|||
the title and subtitle, choose fonts and specify the style for the hello |
|||
world exclamation below. |
|||
</p> |
|||
|
|||
<h2>Hypothesis</h2> |
|||
|
|||
<p> |
|||
Our hypothesis is that generating PDFs using Prince is easy. |
|||
By using a simple document containing only |
|||
<code>h1</code>, |
|||
<code>h2</code>, |
|||
<code>h3</code>, |
|||
<code>p</code>, |
|||
<code>code</code>, |
|||
<code>pre</code>, |
|||
<code>ul</code> and |
|||
<code>li</code> |
|||
tags and a simple stylesheet we will generate a PDF that looks good. |
|||
</p> |
|||
|
|||
<h2>Method</h2> |
|||
<h3>Apparatus</h3> |
|||
|
|||
<ul> |
|||
<li>Prince</li> |
|||
<li>This document</li> |
|||
<li>A stylesheet</li> |
|||
</ul> |
|||
|
|||
<h3>Steps</h3> |
|||
|
|||
Execute this on your computer's command line: |
|||
|
|||
<code><pre> |
|||
$ prince style.css lab_report.html |
|||
</pre></code> |
|||
|
|||
<h2>Results</h2> |
|||
|
|||
<p id="hello">Hello World!</p> |
|||
|
|||
<h2>Conclusions</h2> |
|||
|
|||
<p> |
|||
If you're currently looking at a PDF file then this works. |
|||
</p> |
|||
|
|||
<p> |
|||
The resulting file includes a title and subtitle (centered), a list of the |
|||
apparatus needed. The resulting file uses a sensible-looking a sans-serif |
|||
font except for the code tags which use a monospace font and the Hello World |
|||
exclamation which has serifs. |
|||
</p> |
|||
|
|||
</body> |
|||
</html> |
@ -0,0 +1,28 @@ |
|||
--- |
|||
title: "Example R Markdown" |
|||
output: html_document |
|||
--- |
|||
|
|||
```{r setup, include=FALSE} |
|||
knitr::opts_chunk$set(echo = TRUE) |
|||
``` |
|||
|
|||
## R Markdown |
|||
|
|||
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>. |
|||
|
|||
When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this: |
|||
|
|||
```{r cars} |
|||
summary(cars) |
|||
``` |
|||
|
|||
## Including Plots |
|||
|
|||
You can also embed plots, for example: |
|||
|
|||
```{r pressure, echo=FALSE} |
|||
plot(pressure) |
|||
``` |
|||
|
|||
Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot. |
@ -0,0 +1,12 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/utils-pipe.R |
|||
\name{\%>\%} |
|||
\alias{\%>\%} |
|||
\title{Pipe operator} |
|||
\usage{ |
|||
lhs \%>\% rhs |
|||
} |
|||
\description{ |
|||
See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. |
|||
} |
|||
\keyword{internal} |
@ -0,0 +1,18 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/opts.R |
|||
\name{pr_add_css_file} |
|||
\alias{pr_add_css_file} |
|||
\title{Add CSS files to be included during processing} |
|||
\usage{ |
|||
pr_add_css_file(p, css_paths) |
|||
} |
|||
\arguments{ |
|||
\item{p}{Prince object} |
|||
|
|||
\item{css_paths}{character vector of CSS source paths/URLs. NOTE: |
|||
\code{\link[=path.expand]{path.expand()}} will \emph{not} be run. You are responsible for ensuring |
|||
Prince can find each specified source.} |
|||
} |
|||
\description{ |
|||
Add CSS files to be included during processing |
|||
} |
@ -0,0 +1,17 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/opts.R |
|||
\name{pr_add_css_rules} |
|||
\alias{pr_add_css_rules} |
|||
\title{Add "raw" CSS rules} |
|||
\usage{ |
|||
pr_add_css_rules(p, css_rules) |
|||
} |
|||
\arguments{ |
|||
\item{p}{Prince object} |
|||
|
|||
\item{rule}{character vector of CSS rules. These will be combined into |
|||
a temporary CSS file and included during the render.} |
|||
} |
|||
\description{ |
|||
Add "raw" CSS rules |
|||
} |
@ -0,0 +1,30 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/opts.R |
|||
\name{pr_add_sources} |
|||
\alias{pr_add_sources} |
|||
\title{Add HTML sources to be processed} |
|||
\usage{ |
|||
pr_add_sources(p, source_paths) |
|||
} |
|||
\arguments{ |
|||
\item{p}{Prince object} |
|||
|
|||
\item{source_paths}{character vector of HTML/XML source paths/URLs. NOTE: |
|||
\code{\link[=path.expand]{path.expand()}} will \emph{not} be run. You are responsible for ensuring |
|||
Prince can find each specified source.} |
|||
} |
|||
\description{ |
|||
Add HTML sources to be processed |
|||
} |
|||
\examples{ |
|||
if (interactive()) { |
|||
|
|||
# read from a URL |
|||
|
|||
prince() \%>\% |
|||
pr_enable_js() \%>\% |
|||
pr_add_sources("http://css4.pub/2018/toc") \%>\% |
|||
pr_render(tempfile(fileext = ".pdf", open = TRUE) |
|||
|
|||
} |
|||
} |
@ -0,0 +1,14 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/opts.R |
|||
\name{pr_enable_js} |
|||
\alias{pr_enable_js} |
|||
\title{Enable JavaScript processing} |
|||
\usage{ |
|||
pr_enable_js(p) |
|||
} |
|||
\arguments{ |
|||
\item{p}{Prince object} |
|||
} |
|||
\description{ |
|||
Enable JavaScript processing |
|||
} |
@ -0,0 +1,45 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/raster.R |
|||
\name{pr_raster} |
|||
\alias{pr_raster} |
|||
\title{Render a Prince chain to raster output} |
|||
\usage{ |
|||
pr_raster(pr, output_template, format = c("auto", "png", "jpeg")) |
|||
} |
|||
\arguments{ |
|||
\item{output_template}{location and template for output file. NOTE: |
|||
\code{\link[=path.expand]{path.expand()}} will \emph{not} be run. See |
|||
\href{https://www.princexml.com/doc/command-line/#raster-output-options}{Raster Output Options}} |
|||
|
|||
\item{format}{if \code{auto} then Prince guesses based on file extension in |
|||
\code{output_template}, otherwise specify \code{png} or \code{jpeg}.} |
|||
|
|||
\item{p}{Prince object} |
|||
} |
|||
\description{ |
|||
Render a Prince chain to raster output |
|||
} |
|||
\examples{ |
|||
if (interactive()) { |
|||
prince() \%>\% |
|||
pr_add_sources( |
|||
source_paths = c( |
|||
system.file("examples", "lab-report.html", package = "purplerain") |
|||
) |
|||
) \%>\% |
|||
pr_add_css_rules("body { font-family: sans-serif; }") \%>\% |
|||
pr_add_css_rules(c( |
|||
"h1, h2.subtitle{ text-align: center; }", |
|||
"h2.subtitle { font-size: 14pt; }" |
|||
)) \%>\% |
|||
pr_add_css_rules(" |
|||
#hello { |
|||
color: red; |
|||
text-align: center; |
|||
font-size: large; |
|||
font-style: italic; |
|||
font-family: serif; |
|||
}") \%>\% |
|||
pr_raster(tempfile(pattern = "ex-\%02d", fileext=".png")) |
|||
} |
|||
} |
@ -0,0 +1,37 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/render.R |
|||
\name{pr_render} |
|||
\alias{pr_render} |
|||
\title{Render a Prince chain} |
|||
\usage{ |
|||
pr_render(pr, output_file, open = FALSE) |
|||
} |
|||
\arguments{ |
|||
\item{output_file}{place to put the output PDF (including filename). NOTE: |
|||
\code{\link[=path.expand]{path.expand()}} will \emph{not} be run.} |
|||
|
|||
\item{open}{open the output file (in the system default viewer) after rendering? |
|||
Default: \code{FALSE}.} |
|||
|
|||
\item{p}{Prince object} |
|||
} |
|||
\description{ |
|||
Render a Prince chain |
|||
} |
|||
\examples{ |
|||
#' if (interactive()) { |
|||
rmarkdown::render( |
|||
input = system.file("examples", "r-markdown.Rmd", package = "purplerain"), |
|||
output_file = "/tmp/example.html", |
|||
quiet = TRUE |
|||
) |
|||
|
|||
prince() \%>\% |
|||
pr_add_sources("/tmp/example.html") \%>\% |
|||
pr_render("/tmp/r-markdown.pdf", TRUE) |
|||
|
|||
prince() \%>\% |
|||
pr_add_sources("/tmp/example.html") \%>\% |
|||
pr_raster("/tmp/r-markdown-\%02d.png") |
|||
} |
|||
} |
@ -0,0 +1,16 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/opts.R |
|||
\name{pr_set_input_format} |
|||
\alias{pr_set_input_format} |
|||
\title{Set input format} |
|||
\usage{ |
|||
pr_set_input_format(p, fmt = c("auto", "xml", "html")) |
|||
} |
|||
\arguments{ |
|||
\item{p}{Prince object} |
|||
|
|||
\item{fmt}{one of \code{auto}, \code{xml}, or \code{html}. Defaults to \code{auto}.} |
|||
} |
|||
\description{ |
|||
Set input format |
|||
} |
@ -0,0 +1,24 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/opts.R |
|||
\name{pr_set_pdf_metadata} |
|||
\alias{pr_set_pdf_metadata} |
|||
\title{Set PDF metadata} |
|||
\usage{ |
|||
pr_set_pdf_metadata(p, title, subject, author, keywords, creator) |
|||
} |
|||
\arguments{ |
|||
\item{p}{Prince object} |
|||
|
|||
\item{title}{set document title} |
|||
|
|||
\item{subject}{set document subject} |
|||
|
|||
\item{author}{set document author} |
|||
|
|||
\item{keywords}{set document keywords} |
|||
|
|||
\item{creator}{set document creator} |
|||
} |
|||
\description{ |
|||
Set PDF metadata |
|||
} |
@ -0,0 +1,49 @@ |
|||
% Generated by roxygen2: do not edit by hand |
|||
% Please edit documentation in R/prince.R |
|||
\name{prince} |
|||
\alias{prince} |
|||
\alias{print.prince} |
|||
\title{Start a Prince processing chain} |
|||
\usage{ |
|||
prince(path = Sys.which("prince")) |
|||
|
|||
\method{print}{prince}(x, ...) |
|||
} |
|||
\arguments{ |
|||
\item{path}{fully qualified path to Prince executable. Will attempt |
|||
to find it if no path is specified.} |
|||
|
|||
\item{x}{object} |
|||
|
|||
\item{...}{unused} |
|||
} |
|||
\value{ |
|||
prince object |
|||
} |
|||
\description{ |
|||
Start a Prince processing chain |
|||
} |
|||
\examples{ |
|||
#' if (interactive()) { |
|||
prince() \%>\% |
|||
pr_add_sources( |
|||
source_paths = c( |
|||
system.file("examples", "lab-report.html", package = "purplerain") |
|||
) |
|||
) \%>\% |
|||
pr_add_css_rules("body { font-family: sans-serif; }") \%>\% |
|||
pr_add_css_rules(c( |
|||
"h1, h2.subtitle{ text-align: center; }", |
|||
"h2.subtitle { font-size: 14pt; }" |
|||
)) \%>\% |
|||
pr_add_css_rules(" |
|||
#hello { |
|||
color: red; |
|||
text-align: center; |
|||
font-size: large; |
|||
font-style: italic; |
|||
font-family: serif; |
|||
}") \%>\% |
|||
pr_render(tempfile(fileext=".pdf"), open = TRUE) |
|||
} |
|||
} |
Loading…
Reference in new issue