Closed hansvancalster closed 1 year ago
Below is an attempt. tinytex::check_installed()
is buggy and tinytex::tlmgr_install()
generates false positive errors. Not ideal to integrate in a function.
#' Install all required INBOmd dependencies
#'
#' This installs the `tinytex` package in case is it missing.
#' @family utils
#' @export
#' @importFrom assertthat assert_that
#' @importFrom utils install.packages
install_depedencies <- function() {
if (!requireNamespace("tinytex", quietly = TRUE)) {
install.packages("tinytex")
assert_that(
requireNamespace("tinytex", quietly = TRUE),
msg = "failed to run `install.packages(\"tinytex\")`"
)
}
if (!tinytex:::is_tinytex()) {
tinytex::install_tinytex()
assert_that(
tinytex:::is_tinytex(), msg = "failed to run `tinytex::install_tinytex()`"
)
}
tex_package <- c(
"amsmath", "array", "babel", "booktabs", "calc", "color", "colorbl",
"emptypage", "etoolbox", "eurosym", "fancyvrb", "float", "fontspec",
"footmisc", "framed", "hyperref", "ifxetex", "inconsolata", "inputenc",
"geometry", "graphicx", "kvoptions", "kvsetkeys", "lastpage", "lmodern",
"longtable", "lscape", "makecell", "marginnote", "mdframed", "multicol",
"multirow", "natbib", "needspace", "parskip", "pdfpages", "pdflscape",
"pgf", "placeins", "tabu", "textpos", "threeparttable", "threeparttablex",
"titlesec", "tocloft", "ulem", "upquote", "url", "wrapfig", "xcolor"
)
available <- vapply(tex_package, tinytex::check_installed, logical(1))
tinytex::tlmgr_install(pkgs = tex_package[!available])
c("auxtrees", "add", system.file("local_tex", package = "INBOmd")) |>
tinytex::tlmgr_conf()
return(invisible(NULL))
}
When I run the code in the body of this function, it seems to work (reprex below), but my first attempt which used the function after loading it in the global environment indeed reported errors:
if (!requireNamespace("tinytex", quietly = TRUE)) {
install.packages("tinytex")
assert_that(
requireNamespace("tinytex", quietly = TRUE),
msg = "failed to run `install.packages(\"tinytex\")`"
)
}
if (!tinytex:::is_tinytex()) {
tinytex::install_tinytex()
assert_that(
tinytex:::is_tinytex(), msg = "failed to run `tinytex::install_tinytex()`"
)
}
tex_package <- c(
"amsmath", "array", "babel", "booktabs", "calc", "color", "colorbl",
"emptypage", "etoolbox", "eurosym", "fancyvrb", "float", "fontspec",
"footmisc", "framed", "hyperref", "ifxetex", "inconsolata", "inputenc",
"geometry", "graphicx", "kvoptions", "kvsetkeys", "lastpage", "lmodern",
"longtable", "lscape", "makecell", "marginnote", "mdframed", "multicol",
"multirow", "natbib", "needspace", "parskip", "pdfpages", "pdflscape",
"pgf", "placeins", "tabu", "textpos", "threeparttable", "threeparttablex",
"titlesec", "tocloft", "ulem", "upquote", "url", "wrapfig", "xcolor"
)
available <- vapply(tex_package, tinytex::check_installed, logical(1))
tinytex::tlmgr_install(pkgs = tex_package[!available])
#> tlmgr install array calc color colorbl ifxetex inputenc graphicx lmodern longtable lscape multicol
#> tlmgr update --self
#> tlmgr install array calc color colorbl ifxetex inputenc graphicx lmodern longtable lscape multicol
c("auxtrees", "add", system.file("local_tex", package = "INBOmd")) |>
tinytex::tlmgr_conf()
#> tlmgr conf auxtrees add C:/R/library/INBOmd/local_tex
Created on 2023-03-10 with reprex v2.0.2
e59aea050e4b240 installs TinyTex when missing and add the INBO styles. TinyTeX installs missing generic TeX packages on the fly.
As noted in #87, it can be a good idea to simplify the installation-instructions in the
README.md
by wrapping the latex related stuff of the installation steps into a single functionINBOmd::install_latex()
.This would include:
README.md
+mdframed, zref, needspace, marginnote, babel, babel, babel, carlisle, eurosym, upquote, wrapfig, colortbl, pdflscape, tabu, varwidth, threeparttable, threeparttablex, environ, trimspaces, makecell, footmisc, tocloft, titlesec, ulem, lastpage, fancyhdr, emptypage, placeins, parskip, eso, grfext, oberdiek, pdfpages