This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #' Include an HTML-renderable object in any knitr output format | |
| #' | |
| #' A pipe-friendly helper in Rmarkdown, Quarto, and other documents for objects that render natively in HTML output | |
| #' (RStudio Viewer, HTML documents) but need a convenient image fallback for PDF, Word, | |
| #' and other non-HTML formats. It was designed to solve a problem in rendering the result of `color_table()`, | |
| #' and then generalized to provide for other similar cases. | |
| #' | |
| #' Supported classes (handled internally) solve this problem by saving the image to a file and then inserting it in the document | |
| #' using `knitr::include_graphics()`: | |
| #' - `"gt_tbl"` (gt package) -- saved via \code{\link[gt]{gtsave}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Happy Birthday, R! | |
| # R 1.0.0 was first released on February 29, 2000 | |
| # Celebrating 26 years of statistical computing! | |
| out_file <- "r_birthday_cake.png" | |
| png(out_file, width = 800, height = 660, bg = "#FFF0F5") | |
| par(mar = c(0.3, 0.3, 0.3, 0.3), bg = "#FFF0F5") | |
| plot(0, 0, type = "n", xlim = c(0, 10), ylim = c(0, 10), | |
| axes = FALSE, xlab = "", ylab = "") | |
| rect(-1, -1, 11, 11, col = "#FFF0F5", border = NA) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env Rscript | |
| # Functions to fix one of the awful things that `Rd2roxygen::Rd2roxygen()` does when it tries to convert | |
| # a package to use roxygen documentation | |
| # | |
| # * Fixes roxygen2 \item formatting used in \describe{} blocks to document arguments and elements of returned results | |
| # * Changes \item{list("VarName")} to \item{\code{VarName}} | |
| # | |
| # Usage: | |
| # From R: source("fix_roxygen_items.R"); fix_roxygen_items("R/data.R") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| title: "Distribution of Determinants of 3×3 Matrices from {1,2,...,9}" | |
| author: "Michael Friendly" | |
| date: "`r Sys.Date()`" | |
| output: | |
| html_document: | |
| toc: true | |
| toc_float: true | |
| code_folding: show | |
| theme: united |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #' --- | |
| #' title: discriminant analysis demo | |
| #' author: Michael Friendly | |
| #' --- | |
| library(MASS) | |
| library(ggplot2) | |
| #library(candisc) | |
| library(dplyr) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Accumulating R package references in a Quarto book | |
| In writing a book using Quarto, I was looking for a way to automatically | |
| accumulate the packages used in each chapter and write them out to a `pkgs.bib` | |
| file at the end. (I posted this as a Posit Community question, | |
| https://community.rstudio.com/t/how-to-accumulate-packages-bib-used-in-a-quarto-book/167619 ) | |
| I can easily do this with a `knitr` vignette, where the essence | |
| is to include a chunk at the end, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #' Render text in color for Markdown / Quarto documents using LaTeX or CSS styles | |
| #' | |
| #' This function uses `\textcolor{}{}` from the `xcolor` package for LaTeX output | |
| #' or a CSS `<span>` for HTML output. | |
| #' | |
| #' Note that a color not defined in the `xcolor` package will trigger a latex error. | |
| #' e.g., `darkgreen` is not defined but can use: | |
| #' \definecolor{darkgreen}{RGB}{1,50,32} | |
| #' | |
| #' @param text Text to display, a character string |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #' --- | |
| #' title: penguin colors | |
| #' author: Michael Friendly | |
| #' --- | |
| # Create consistent sets of colors for penguins examples | |
| # These specific colors are taken from https://github.com/srvanderplas/ggpcp-paper/blob/main/index.R | |
| # See the image at: https://allisonhorst.github.io/palmerpenguins/reference/figures/lter_penguins.png | |
| peng.colors <- function(shade=c("medium", "light", "dark")) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #' Generate Outline Documentation for a Data Set in Roxygen Format | |
| #' | |
| #' Generates a shell of documentation for a data set or other object in roxygen format. | |
| #' This function was created by editing \code{\link[utils]{promptData}} to replace | |
| #' the old style \code{.Rd} formatting with code suitable for processing with \code{\link[devtools]{document}}. | |
| #' | |
| #' @details | |
| #' Unless \code{filename} is \code{NA}, a documentation shell for \code{object} is written in roxygen format to the file specified | |
| #' by \code{filename}, and a message about this is given. | |
| #' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #' --- | |
| #' title: Animate transition from PCA <--> tsne | |
| #' --- | |
| # idea from: https://jef.works/genomic-data-visualization-2024/blog/2024/03/06/akwok1/ | |
| #' ## Load packages and data | |
| library(ggplot2) | |
| library(gganimate) | |
| library(Rtsne) | |
| library(patchwork) |
NewerOlder