#' Title
#'
#' @param write_file Defaults to true,and writes a Dockerfile at the path (and filename)
#' you choose. If you instead select 'F', the output will be written to the console
#' (or whatever connection you currently have open). Writing a file will overwrite
#' any Dockerfile in the same location. 'T' is probably appropriate for exporting to
#' a tool like mybinder.org, 'F' is appropriate if you already have a Dockerfile
#' and you just want to cut and paste sections from this function into it.
#' @param org Defaults to Rocker (https://www.rocker-project.org/), but you can choose
#' whichever group you like; the Dockerfile will probably only work as the basis for a
#' Docker container if the underlying image comes with `r`.
#' You can leave this parameter blank if, for instance, you want to access Docker's official
#' R images, available here: https://hub.docker.com/_/r-base
#' @param image Defaults to r-base:latest, whose source code is on Rocker's GitHub:
#' currently, https://github.com/rocker-org/rocker/blob/master/r-base/latest/Dockerfile.
#' available tags r-base are listed here: https://hub.docker.com/r/rocker/r-base/tags,
#' and help with installing previous versions of R.
#' Other Rocker images can be browsed here: https://hub.docker.com/u/rocker
#'
#' @param dir Defaults to current directory, './'.
#' @param filename Defaults to 'Dockerfile', making the composite file
#' './Dockerfile'.
#'
#' @return
#' @export
#'
#' @examples session_info_converter()
#' session_info_converter(write_file = F, image = 'geospatial')
session_info_converter <- function(write_file = T,
org = "rocker",
image = "r-base:latest",
dir = './',
filename = 'Dockerfile'){
if(isTRUE(write_file)){
Dockerfile = paste0(dir, filename)
file.create(Dockerfile)
sink(file = Dockerfile, append = T)
}
cat(paste0("FROM ", org, "/", image, "\n", "\n"))
cat(paste0("ARG DEBIAN_FRONTEND=noninteractive", "\n", "\n"))
cat(paste0("RUN Rscript -e 'if (!require(\"remotes\")) install.packages(\"remotes\")'", "\n"))
for(pkg in sort(names(sessionInfo()$otherPkgs))){
cat(paste0(noquote("RUN Rscript -e '"),
noquote("remotes::install_version(package = "), '"', pkg, '"',
",", " version = ", getNamespaceVersion(pkg), ")", "\n"))
}
if(isTRUE(write_file)){
sink()
}
}
session_info_converter()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.