### TinyTeX - Installation and Setup Source: https://context7.com/yihui/yihui.org/llms.txt Guides on installing and setting up TinyTeX, a lightweight LaTeX distribution for R users, including R package and shell commands. ```APIDOC ## TinyTeX - Installation and Setup ### Description Install and configure TinyTeX, a lightweight LaTeX distribution optimized for R users that automatically manages missing packages. ### Method R Function Call / Shell Command ### Endpoint N/A (Installation commands) ### Parameters - **bundle** (string) - Optional - Specifies the package bundle to install (e.g., 'TinyTeX-2' for a full bundle). ### Request Example ```r # Install tinytex R package install.packages('tinytex') # Install TinyTeX distribution (basic) tinytex::install_tinytex() # Install TinyTeX distribution (full bundle) tinytex::install_tinytex(bundle = 'TinyTeX-2') # Uninstall TinyTeX tinytex::uninstall_tinytex() # Reinstall (preserves installed packages) tinytex::reinstall_tinytex() # Check if TinyTeX is installed tinytex::is_tinytex() # Get TinyTeX root directory tinytex::tinytex_root() ``` ```bash # Shell installation for Linux/macOS curl -sL "https://tinytex.yihui.org/install-bin-unix.sh" | sh # Uninstall from command line (Linux) tlmgr path remove rm -r ~/.TinyTeX # Uninstall from command line (macOS) tlmgr path remove rm -r ~/Library/TinyTeX ``` ### Response N/A (Installs software ``` -------------------------------- ### R Package Installation Example Source: https://github.com/yihui/yihui.org/blob/master/content/en/2026-01-23-hello-world.md Demonstrates how to install R packages 'crayon' and 'glue' using the install.packages function. This is a common task for R users managing their package environment. ```R install.packages(c('crayon', 'glue')) ``` -------------------------------- ### Configure Knitr Settings via opts_knit Source: https://github.com/yihui/yihui.org/blob/master/content/knitr/objects.md Demonstrates how to initialize knitr settings within a setup chunk. This example sets the upload function, disables self-contained output, and defines the root directory. ```r <>= library(knitr) opts_knit$set(upload.fun = imgur_upload, self.contained = FALSE, root.dir = '~/R/project') @ ``` -------------------------------- ### Install system dependencies and R packages Source: https://github.com/yihui/yihui.org/blob/master/content/en/2018-07-01-cranextra-macos.md Uses system commands to install required Homebrew dependencies followed by the installation of the R package rattle. This streamlines the setup process for packages with complex system requirements. ```r system('brew install gtk+') install.packages('rattle') ``` -------------------------------- ### Install and Configure TinyTeX Source: https://context7.com/yihui/yihui.org/llms.txt Procedures for installing TinyTeX system-wide, setting up user-mode environments, and managing portable installations on external drives. ```bash wget -qO- "https://tinytex.yihui.org/install-unx.sh" | sh -s - --admin --no-path sudo ~/.TinyTeX/bin/*/tlmgr path add tlmgr init-usertree tlmgr --usermode install koma-script xcolor ``` ```R tinytex::copy_tinytex(to = "/Volumes/USB/TinyTeX") tinytex::use_tinytex(from = "/Volumes/USB/TinyTeX") tinytex::install_tinytex(dir = "/opt/latex") ``` -------------------------------- ### Automatic Package Installation with xfun::pkg_attach Source: https://github.com/yihui/yihui.org/blob/master/content/en/2018-09-04-xfun-pkg-attach.md Shows how to automatically install and load missing packages using the install = TRUE argument or the pkg_attach2() shorthand. This is useful for ensuring dependencies are present without manual intervention. ```r xfun::pkg_attach(c('ggplot2', 'dplyr', 'shiny'), install = TRUE) xfun::pkg_attach2(c('ggplot2', 'dplyr', 'shiny')) ``` -------------------------------- ### Install RGtk2 from Source with Custom Environment Variables Source: https://github.com/yihui/yihui.org/blob/master/content/en/2018-01-26-install-rgtk2-macos.md A manual workaround for installing RGtk2 from source when binary installation is not feasible. It sets the PKG_CONFIG_PATH environment variable to locate necessary system header files. ```r Sys.setenv(PKG_CONFIG_PATH = paste( "/usr/local/lib/pkgconfig", "/usr/local/lib/pkgconfig/gtk+-2.0.pc", "/opt/X11/lib/pkgconfig", sep = ":" )) install.packages("RGtk2") ``` -------------------------------- ### Install formatR Package Source: https://github.com/yihui/yihui.org/blob/master/content/pkg-formatR.md Demonstrates how to install the formatR package from CRAN or the development version from yihui's r-universe repository. ```r install.packages("formatR", repos = "http://cran.rstudio.com") # or development version options(repos = c(yihui = "https://yihui.r-universe.dev", CRAN = "https://cloud.r-project.org")) install.packages("formatR") ``` -------------------------------- ### Install LyX via PPA on Ubuntu Source: https://github.com/yihui/yihui.org/blob/master/content/knitr/demo/2011-12-06-lyx.md Recommended commands to add the official LyX PPA repository and install the latest version of LyX on Ubuntu. ```bash sudo add-apt-repository ppa:lyx-devel/release sudo apt-get update sudo apt-get install lyx ``` -------------------------------- ### ImageMagick Path and GIF Conversion Example in R Source: https://github.com/yihui/yihui.org/blob/master/content/en/2010-03-28-looking-for-software-paths-in-windows-registry.md This R code snippet demonstrates finding the ImageMagick binary path from the registry and using it to convert a sequence of R-generated PNG images into a GIF animation. It requires the 'animation' package and assumes ImageMagick is installed. ```R ## find the bin path of ImageMagick magick.path = readRegistry("SOFTWARE\ImageMagick\Current")$BinPath if (nzchar(magick.path) && require(animation)) { convert = shQuote(normalizePath(file.path(magick.path, "convert.exe"))) ## record the demo 'recur.tree' in png images png("magickEx%d.png") demo(recur.tree) dev.off() ## call convert.exe to convert png images to GIF cmd = paste(sprintf("%s -delay", convert), 100, "-loop 0 magickEx*.png magickEx.gif") ## try to open the GIF animation if (system(cmd) == 0) shell.exec(file.path(getwd(), "magickEx.gif")) } ``` -------------------------------- ### Checking Package Availability and Installing in R Source: https://github.com/yihui/yihui.org/blob/master/content/en/2018-09-04-xfun-pkg-attach.md Illustrates the common pattern in R of explicitly checking if a package is installed before attempting to install it, which is a workaround for the lack of direct support in base R functions. ```r if (!requireNamespace('package_name', quietly = TRUE)) { install.packages('package_name') } ``` -------------------------------- ### Install TinyTeX on Windows Source: https://github.com/yihui/yihui.org/blob/master/content/tinytex/_index.md Instructions for installing TinyTeX on Windows. Users can download and run an installation batch file, or use package managers like Chocolatey or Scoop. The installation requires PowerShell version 3.0 or higher. The installation directory is typically within the user's APPDATA folder. ```batch rem Save install-bin-windows.bat and double click it. rem Requires PowerShell (at least version 3.0). rem Installation directory is %APPDATA%/TinyTeX. ``` -------------------------------- ### Clean Bash and R Code Examples Source: https://github.com/yihui/yihui.org/blob/master/content/en/2013-01-26-code-pollution-with-command-prompts.md Examples of executable code snippets stripped of command prompts, demonstrating the preferred format for documentation. ```bash jhbuild bootstrap jhbuild build meta-gtk-osx-bootstrap jhbuild build meta-gtk-osx-core ``` ```r data("bodyfat", package = "mboost") str(bodyfat) ``` -------------------------------- ### Install TinyTeX on Linux/macOS via Shell Script Source: https://github.com/yihui/yihui.org/blob/master/content/tinytex/_index.md This code demonstrates how to install TinyTeX on Linux and macOS systems using a shell script downloaded via wget or curl. It includes commands to ensure Perl is installed, download the installation script, and execute it. For macOS, it also includes an optional command to change ownership of /usr/local/bin to allow symlinking TeX Live executables. ```sh # make sure perl is properly installed (e.g., apt install -y perl) perl -m::Find /dev/null # then install TinyTeX wget -qO- "https://tinytex.yihui.org/install-bin-unix.sh" | sh ``` ```sh curl -sL "https://tinytex.yihui.org/install-bin-unix.sh" | sh ``` -------------------------------- ### Install TinyTeX for All Users on Linux Source: https://github.com/yihui/yihui.org/blob/master/content/tinytex/faq.md Commands to install TinyTeX in a shared directory and configure system-wide access via symlinks in /usr/local/bin. ```sh wget -qO- "https://tinytex.yihui.org/install-unx.sh" | sh -s - --admin --no-path sudo ~/.TinyTeX/bin/*/tlmgr path add ``` -------------------------------- ### Configure TeX Live Installation Options Source: https://github.com/yihui/yihui.org/blob/master/content/tinytex/faq.md Configuration settings used within the tinytex.profile to minimize installation size by excluding documentation and source files. ```config option_doc 0 option_src 0 ``` -------------------------------- ### Install and Load xfun for File Embedding Source: https://github.com/yihui/yihui.org/blob/master/content/en/2018-07-11-embed-file.md Instructions for installing the development version of the xfun package and loading the necessary dependencies required for file embedding functionality. ```R remotes::install_github('yihui/xfun') # embed_file() requires a few more packages xfun::pkg_load2(c('htmltools', 'mime')) ``` -------------------------------- ### OpenBUGS Path and R2WinBUGS Example in R Source: https://github.com/yihui/yihui.org/blob/master/content/en/2010-03-28-looking-for-software-paths-in-windows-registry.md This R code snippet finds the OpenBUGS directory from the Windows Registry and then uses it to run a Bayesian analysis example with the R2WinBUGS and BRugs packages. It requires OpenBUGS, R2WinBUGS, and BRugs to be installed. ```R r = names(readRegistry( "Software\Microsoft\Windows\ShellNoRoam\MUICache", "HCU" )) bugsDIR = dirname(r[grep("OpenBUGS\.exe", r)]) if (length(bugsDIR) == 1) { library(R2WinBUGS) library(BRugs) ## this example comes from ?bugs in R2WinBUGS model.file = system.file(package = "R2WinBUGS", "model", "schools.txt") data(schools) J = nrow(schools) y = schools$estimate sigma.y = schools$sd data = list("J", "y", "sigma.y") inits = function() { list(theta = rnorm(J, 0, 100), mu.theta = rnorm(1, 0, 100), sigma.theta = runif(1, 0, 100)) } parameters = c("theta", "mu.theta", "sigma.theta") schools.sim = bugs(data, inits, parameters, model.file, n.chains = 3, n.iter = 5000, bugs.directory = bugsDIR, program = "OpenBUGS") print(schools.sim) plot(schools.sim) } ``` -------------------------------- ### Install Hugo for specific OS and architecture Source: https://github.com/yihui/yihui.org/blob/master/content/en/2021-11-12-blogdown-v1-6.md Demonstrates how to manually specify the operating system and architecture when the automatic detection in install_hugo() fails. This is useful for systems like FreeBSD that may not be automatically detected. ```R blogdown::install_hugo(os = 'FreeBSD', arch = '64bit', extended = F) ``` -------------------------------- ### Play Five in a Row in R using the 'fun' package Source: https://github.com/yihui/yihui.org/blob/master/content/en/2011-08-16-the-fun-package-use-r-for-fun.md This R code snippet shows how to load the 'fun' package and start the 'Five in a Row' (Gomoku) game. It requires the 'fun' package to be installed. The function 'gomoku()' is called to initiate the game. ```r library(fun) gomoku() ``` -------------------------------- ### Attempting to Load Multiple Packages with require() in R Source: https://github.com/yihui/yihui.org/blob/master/content/en/2014-07-26-library-vs-require.md Illustrates the behavior of `require()` when attempting to load multiple packages simultaneously by passing a vector of package names. This example shows that `require()` returns FALSE and may produce warnings or errors, regardless of whether the packages are installed, due to its design which expects a single package name. ```r > (require(c('MASS', 'nnet'))) c("Loading required package: c", "Loading required package: MASS", "Loading required package: nnet") Failed with error: ‘'package' must be of length 1’ In addition: Warning message: In if (!loaded) { : the condition has length > 1 and only the first element will be used [1] FALSE > (require(c('MASS', 'nnet'), character.only = TRUE)) c("Loading required package: MASS", "Loading required package: nnet") Failed with error: ‘'package' must be of length 1’ In addition: Warning message: In if (!loaded) { : the condition has length > 1 and only the first element will be used [1] FALSE ``` -------------------------------- ### Install Full TinyTeX Bundle via Shell Source: https://github.com/yihui/yihui.org/blob/master/content/en/2022-05-19-tinytex-full.md This snippet shows how to trigger the installation of the full TinyTeX-2 bundle using environment variables in a shell or batch script environment. ```bash export TINYTEX_INSTALLER=TinyTeX-2 # Run the installation script after setting the variable ``` -------------------------------- ### Pandoc Command Line Example Source: https://github.com/yihui/yihui.org/blob/master/content/knitr/demo/2013-03-06-pandoc.md Illustrates a typical Pandoc command-line invocation for converting a Markdown file to HTML, including options for math rendering, section numbering, bibliography, and output file specification. ```bash pandoc -s --mathjax --number-sections --bibliography=foo.bib \ -o output.html input.md ``` -------------------------------- ### Install texlive-local.deb to Prevent System TeX Live Installation (Shell) Source: https://github.com/yihui/yihui.org/blob/master/content/tinytex/faq.md This script downloads and installs a dummy debian package to prevent package managers like apt-get from installing the full TeX Live distribution when other packages depend on it. It then cleans up the downloaded file. ```sh wget "https://github.com/rstudio/tinytex-releases/releases/download/daily/texlive-local.deb" sudo dpkg -i texlive-local.deb rm texlive-local.deb ``` -------------------------------- ### Install R Animation Package Source: https://github.com/yihui/yihui.org/blob/master/content/animation/_index.md Provides R code to install the 'animation' package. It shows how to install the stable version from CRAN and the development version from GitHub using the 'remotes' package. ```r install.packages('animation') # or development version # remotes::install_github('yihui/animation') ``` -------------------------------- ### Vectorized Package Loading with xfun::pkg_attach Source: https://github.com/yihui/yihui.org/blob/master/content/en/2018-09-04-xfun-pkg-attach.md Demonstrates how to replace multiple library() calls with a single vectorized call to xfun::pkg_attach(). This approach avoids non-standard evaluation and simplifies package management. ```r xfun::pkg_attach(c('ggplot2', 'dplyr', 'shiny')) ``` -------------------------------- ### Setting up GitHub Action for Debugging with tmate Source: https://github.com/yihui/yihui.org/blob/master/content/en/2022-12-21-gha-debug.md This YAML configuration sets up a GitHub Action workflow that installs R, Pandoc, and TinyTeX, then uses the `tmate` action to provide SSH access to the virtual machine for debugging. It allows customization of the operating system (Ubuntu, Windows, macOS) and R version (devel, release, oldrel-1). ```yaml name: Debug R problems on: [push] jobs: debug: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Setup R uses: r-lib/actions/setup-r@v2 with: r-version: 'devel' - name: Install Pandoc uses: r-lib/actions/setup-pandoc@v2 - name: Install TinyTeX run: | Rscript -e 'tinytex::install_tinytex()' - name: Setup tmate session uses: mxschmitt/action-tmate@v3 ``` -------------------------------- ### Install TinyTeX and R Markdown dependencies Source: https://github.com/yihui/yihui.org/blob/master/content/en/2017-12-04-test-tinytex.md This snippet installs the tinytex and rmarkdown R packages from GitHub and triggers the installation of the TinyTeX distribution. It is recommended to uninstall existing LaTeX distributions before running these commands. ```r # before installing TinyTeX, it will be great if you can uninstall # your existing LaTeX distribution remotes::install_github(c("rstudio/tinytex", "rstudio/rmarkdown")) tinytex::install_tinytex() ``` -------------------------------- ### Install TinyTeX with Custom Directory (R) Source: https://github.com/yihui/yihui.org/blob/master/content/tinytex/faq.md This R function allows users to install TinyTeX in a custom directory by specifying the 'dir' argument. This is useful for managing multiple TeX distributions or for installing on non-standard locations. ```r tinytex::install_tinytex(dir = "/path/to/custom/directory") ``` -------------------------------- ### R Code Formatting with formatR Source: https://github.com/yihui/yihui.org/blob/master/content/en/2010-04-13-formatr-farewell-to-ugly-r-code.md Demonstrates how to install and load the formatR package, and then use its GUI function `tidy_gui()` to format R code. It also shows how to install a dependency if needed. ```r # formatR optionally depends on gWidgetsRGtk2 # please use the latest version of R (>=2.12.0) install.packages('formatR') library(formatR) tidy_gui() ## you will get an error if the package gWidgetsRGtk2 is not installed; ## then you need to install it install.packages('gWidgetsRGtk2') tidy_gui('RGtk2') ``` -------------------------------- ### Import Keyboard Styling Assets Source: https://github.com/yihui/yihui.org/blob/master/content/en/2023-02-22-key-buttons.md Include the necessary JavaScript and CSS files via CDN to enable automatic conversion of tags to elements and apply button styling. ```html ``` -------------------------------- ### Copy TinyTeX Installation to a New Location Source: https://github.com/yihui/yihui.org/blob/master/content/en/2018-08-31-tinytex-flash-drive.md Copies an existing TinyTeX installation to a specified destination, such as a flash drive or cloud storage. This function is useful for creating a portable LaTeX environment. It requires TinyTeX to be installed prior to execution. ```R tinytex::copy_tinytex('E:/Software/') ``` -------------------------------- ### Install and Manage TinyTeX with R Package Source: https://github.com/yihui/yihui.org/blob/master/content/tinytex/_index.md This snippet shows how to install, manage, and use the TinyTeX LaTeX distribution via the R package 'tinytex'. It includes functions for installing TinyTeX itself, uninstalling it, and compiling LaTeX documents using different engines like pdflatex, xelatex, and lualatex. The R package can automatically install missing LaTeX packages when compiling documents. ```r install.packages('tinytex') tinytex::install_tinytex() tinytex::uninstall_tinytex() # writeLines(c( # '\\documentclass{article}', # '\\begin{document}', 'Hello world!', '\\end{document}' # ), 'test.tex') tinytex::pdflatex('test.tex') ``` ```r tinytex:::install_yihui_pkgs() ``` -------------------------------- ### Programmatically Embed Files Source: https://github.com/yihui/yihui.org/blob/master/content/en/2018-07-11-embed-file.md Demonstrates how to dynamically select and embed files using pattern matching with list.files. ```R # embed all Rmd and csv files xfun::embed_files(list.files('.', '[.](Rmd|csv)$')) ``` -------------------------------- ### Add TinyTeX to PATH after Moving Installation (Shell) Source: https://github.com/yihui/yihui.org/blob/master/content/tinytex/faq.md These commands demonstrate how to update the system's PATH variable to include the TinyTeX binaries after the installation directory has been moved. The specific path to tlmgr depends on the operating system and the new installation location. ```sh # assume you moved ~/.TinyTeX on Linux to /opt/tinytex /opt/tinytex/bin/*/tlmgr path add # assume you moved ~/Library/TinyTeX on macOS to /opt/tinytex /opt/tinytex/bin/*/tlmgr path add # assume you moved %APPDATA%\TinyTeX on Windows to C:\\Software\\TinyTeX "C:\\Software\\TinyTeX\\bin\\win32\\tlmgr" path add ``` -------------------------------- ### Perform R Help Searches Source: https://github.com/yihui/yihui.org/blob/master/content/pkg-printr.md Examples of using the help.search function or the ?? operator to find documentation topics within R packages. ```R ??sunflower help.search('contourplot') help.search('foo', package = 'base') help.search('foooooooo', package = 'utils') ``` -------------------------------- ### Install xfun Development Version Source: https://github.com/yihui/yihui.org/blob/master/content/en/2018-02-02-typing-fast.md Command to install the development version of the xfun package which contains the polished rstudio_type function. ```r remotes::install_github('yihui/xfun') ``` -------------------------------- ### R: Example of a function and its roxygen documentation Source: https://github.com/yihui/yihui.org/blob/master/content/pkg-Rd2roxygen.md This snippet shows an example R function 'parse_and_save' and its corresponding roxygen2-style documentation comments. It demonstrates how documentation is written as inline comments preceding the function definition. ```r ## the source code of the function `parse_and_save` ex.file = system.file('examples', 'parse_and_save.R', package = 'Rd2roxygen') xfun::file_string(ex.file) ``` ```r #' Parse the input Rd file and save the roxygen documentation into a file. #' #' @param path the path of the Rd file #' @param file the path to save the roxygen documentation #' @param usage logical: whether to include the usage section in the output #' @return a character vector if \code{file} is not specified, or write the #' vector into a file #' @export #' @author Hadley Wickham; modified by Yihui Xie <\url{http://yihui.org}> parse_and_save <- function(path, file, usage = FALSE) { parsed <- parse_file(path) output <- create_roxygen(parsed, usage = usage) if (missing(file)) output else cat(paste(output, collapse = "\n"), file = file) } ``` -------------------------------- ### Install and Manage TinyTeX Distribution Source: https://context7.com/yihui/yihui.org/llms.txt Covers the installation, uninstallation, and verification of the TinyTeX LaTeX distribution across R and shell environments. ```R install.packages('tinytex') tinytex::install_tinytex() tinytex::is_tinytex() ``` ```bash wget -qO- "https://tinytex.yihui.org/install-bin-unix.sh" | sh curl -sL "https://tinytex.yihui.org/install-bin-unix.sh" | sh ``` -------------------------------- ### R Markdown Presentation Setup Source: https://github.com/yihui/yihui.org/blob/master/content/en/2018-05-25-github-issue-format.md This R Markdown code block demonstrates the setup for a presentation using the xaringan package. It includes options to control the inclusion of HTML versions and other presentation-specific configurations. ```r \`\`\`{r setup, include=FALSE} options(htmltools.dir.version = FALSE) \`\`\` ```